• 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 add automatically collapse/expand in content wordpress (single.php)?

Mysqli multi query error

CodeIgniter 3 is generating a session file on each request, why?

PHP mail function is sending blank message body

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

How to programmatically find public properties of a class from inside one of it's methods

How to get array values using foreach in laravel

Laravel Command Schedule Not Working Properly

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

Problems getting instance of UploadedFile in Yii2

Sentry + Laravel: how to log an already catched Exception?

Laravel MSSQL Server Connection not working

Laravel print last executed SQL query with Query log

PHP contact form configuration [duplicate]

Get image type from base64 encoded src string

About Contact Privacy policy Terms and conditions