• 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 pass data to all views in Laravel 5?

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

How to debug in WooCommerce 3+

PHP: How to quickly split a key=value file into associative array

WordPress + Nginx on non-standard port behind AWS ELB results in broken links

Add restriction to WooCommerce coupons by allowed user ID

How to set a domain name with php artisan serve

Assets not referencing to public folder (Laravel)

Open a popup box after receiving result from ajax

Need to display only array value in JSON output

Problems getting instance of UploadedFile in Yii2

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

Transpose and flatten two-dimensional indexed array where rows may not be of equal length

Doctrine 2 mapping referencing unique key

Pass an image through AJAX [duplicate]

About Contact Privacy policy Terms and conditions