• 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

How to set dynamic `home` and `siteurl` in WordPress?

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

PHP: Print caught exception like Xdebug

How to put php code inside opening and closing shortcodes

PHP each() function replacement

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

Make Shipping Method fields Mandatory on Woocommerce checkout page

How can I pass the list to the component variable in Laravel?

WooCommerce Additional Information - if empty, hide

Multiple order by in WooCommerce

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

merging two arrays with specified index

SlimExceptionHttpNotFoundException

Make certain characters of a word from string bold

Laravel 8: Array to string conversion while calling route:list

About Contact Privacy policy Terms and conditions