• 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

jQuery Ajax Post with data

how do i retrieve and display the alt text of an image in wordpress?

sqlsrv_num_rows() expects parameter 1 to be resource, boolean given

Show Custom Data in Woocommerce Order Details Admin Area

Alert message after submitting form in PHP

Dynamic dropdown Ajax PHP request

Adding the custom page with add_menu_page function on Wordpress

Don't show recurring price for WooCommerce subscriptions worth 0$

I want to display a sweetalert after the inserting of data in my database

How to get monthly wise data in laravel

merging two arrays with specified index

Exact alternate to mcrypt_encrypt in PHP 7.2

WAMP Virtual Host not working

How to insert data from multiple select dropdown values into database?

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

About Contact Privacy policy Terms and conditions