• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

phpwordpresswoocommercehook-woocommercestock


PHP Snippet 1:

add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2 );
function filter_product_availability_text( $availability_text, $product ) {

    if( $product->is_in_stock() && $product->managing_stock() && 
    ! $product-> is_on_backorder( 1 ) && $product->get_stock_quantity() < 10 ) {
        $availability_text .= ' ' . __("(limited supply left)", "woocommerce");
    }
    return $availability_text;
}

Related Snippets

How to downgrade or install a specific version of Composer?

Assign output of PHP function to a variable

Increase value by 1 on button click

storagelogs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

Laravel 8 Multiple Relationships for Factory

Attempt to read property "view" on null when sending password reset email

how do i retrieve and display the alt text of an image in wordpress?

how to see if database exists with PDO [duplicate]

Sagepay Error The Vendor failed to provide a RedirectionURL

XDebug not working in VScode for php debugging

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

How can I remove the "Advanced" panel of all blocks in WordPress block editor?

How to install php_imagick on wamp64

How to test laravel controller method?

How to override header set in Apache config with more specific header in a virtual host

About Contact Privacy policy Terms and conditions