• 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

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

Display the WooCommerce product price inside a custom function

Laravel php artisan serve to mimic HTTPS

Add a custom text for a particular product on specific email notification in Woocommerce

how to check version of codeigniter framework?

str_word_count() function doesn't display Arabic language properly

html-php form submission after validation through JavaScript [closed]

PHP web3 ERC20 token function call

Laravel - How to properly generate unique slugs from article titles?

Cannot pass null argument when using type hinting

Statement that checks whether a URL contains a particular path?

PHP if in_array() how to get the key as well?

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

If action is on a different page do I use fwrite function

Add 2 Webcam in one page with WebcamJS

About Contact Privacy policy Terms and conditions