• 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 display validation error

MySQL/PHP - Web Based Game -User specific inventory table or 1 giant table? Another option?

Artisan, creating tables in database

Filter WooCommerce related products by Polylang language

Apply filter array/return terms

WooCommerce Additional Information - if empty, hide

How to get total pages of PDF with FPDF?

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

How to show selected value using javascript in laravel

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

What is PHP's equivalent of JavaScript's "array.every()"?

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

stay with the last 15 elements of an array [duplicate]

How to convert the int value to inch in PHP [closed]

WooCommerce Additional Information - if empty, hide

About Contact Privacy policy Terms and conditions