• 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

PHP date() with timezone?

Laravel websockets AWS EC2 - Connection failed

Magento 2 - How to add new block to admin panel in product page?

Display the default discounted price and percentage on Woocommerce products

Return new collection without modifying original collection

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

Facebook API, get page post link (PHP)

Telegram bot doesn't answer

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

How to add a sidebar to Woocommerce Shop Page?

How to use a PHP MVC Controller, one thats invoked by calling a URL, to call and execute more than one function? [duplicate]

Check if string contains a value in array [duplicate]

Having trouble with PDO queries (Notice: Undefined index)

How to delete old images from public folder on update using Laravel

About Contact Privacy policy Terms and conditions