• 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

Cut an arabic string

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

virtctl works when executed via command line but not from php exec()

Custom add to cart button URL for specific product in WooCommerce?

Wordpress add responsive srcset header image to theme

WooCommerce - unset "<product> removed notice…" on cart page

Convert every two values of an associative array into key-value pairs

Sentry on Symfony: how to exclude `NotFoundHttpException`

Add customer email and phone in "Order" column to admin orders list on Woocommerce

Creating live search with AJAX and CodeIgniter

Multiple order by in WooCommerce

Put content of wordpress page inside div

How can I stop a symfony process which is listening on http://127.0.0.1:8000

XAMPP/SQLSRV: Unable to find Sqlsrv in PHPINFO(); - errors coming from connection

str_word_count() function doesn't display Arabic language properly

About Contact Privacy policy Terms and conditions