• 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

Symfony/Form add attribute based on the data

How to keep value of selected value after form submission?

Laravel Multi-language routes without prefix

args[max_input] woocommerce if statement confused

Change the alert text on add to cart action without selected variation in Woocommerce

Display a product custom field only in WooCommerce Admin single orders

How to change the app environment at run time?

(Cache::lock()) -> get() -- Under what conditions does it return false?

Call to a member function fetch_field() on a non-object MySQLiDB

How can I access an array/object?

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

json_encode turns array into an object

Display a success custom notice after Placing an Order in WooCommerce

Laravel 5.2: Unable to locate factory with name [default]

Display a product custom field only in WooCommerce Admin single orders

About Contact Privacy policy Terms and conditions