• 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

str_word_count() function doesn't display Arabic language properly

backup files to google drive using PHP

How to debug in WooCommerce 3+

How to validate Envato Purchase Code in PHP

SQL to convert multiple rows into a single row of variable length

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

Encrypt in php and decrypt in Dart(flutter)

Creating Combinations of Elements

Natural ORDER in Laravel Eloquent ORM

PHP Download MP3 files from directory on server

Laravel/ PHP: Order By Alphabetical with numbers in order [duplicate]

PHP: How to solve ob_start() in combination imagepng() issue?

How to fix bootstrap multiselect search data using ajax

Adding custom body class to the custom archive pages

Laravel 8 Multiple Relationships for Factory

About Contact Privacy policy Terms and conditions