• 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

Laravel 5 controller sending JSON integer as string

Get WooCommerce product variation attribute terms in admin products general box

How to execute sql code based on fetch array

Clients authentication and user authentication with laravel

Get orders by date and status woocommerce

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

How can I remove the "Advanced" panel of all blocks in WordPress block editor?

Split a string array into pieces

PHP: Print caught exception like Xdebug

Laravel Excel::store file empty after stored

WooCommerce Subscriptions: Remove role on cancelled subscription

woocommerce get_order_report_data to show order_item_id

How can I create a Download Page with post php method?

Woocommerce redirect after add-to-cart error

PHP each() function replacement

About Contact Privacy policy Terms and conditions