• 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

Phpunit partial mock + proxy Entity

Problems getting instance of UploadedFile in Yii2

PHP: Insert marker every 3 iterations

Execute only one time and then wait set period of time before executing again

how to youtube api data to print in toolset metabox using a button click before save-post

Display specific shipping method if woocommerce product has specific acf field value

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Filter array by skipping every nth element from the end

500 (Internal Server Error) with Laravel & Docker [duplicate]

The sum of the user's points

Error when uploading certain .png files "Interlace handling should be turned on when using png_read_image"

Upgrade PHP on AWS Linux

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

How to change product Image when variables are selected in Shop and Archive Pages?

Put content of wordpress page inside div

About Contact Privacy policy Terms and conditions