• 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

Losing session data after POST from third party website

Get all WooCommerce products within own plugin

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

Composer Script echo

PHP how to detect if running on arm64 cpu?

PHP mail sending empty mails

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

Laravel insert dynamic input values with radio button

Chunk and transpose a flat array into rows with a specific number of columns

How can I make this nested location configuration use the correct path to call a php program?

Transpose csv file data [duplicate]

laravel sanctum Route [login] not defined

Show Custom Data in Woocommerce Order Details Admin Area

How to skip cart page on woocomerce for certain products only?

Display the default discounted price and percentage on Woocommerce products

About Contact Privacy policy Terms and conditions