• 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

Add a custom text for a particular product on specific email notification in Woocommerce

Apply filter array/return terms

PHP Download MP3 files from directory on server

How to add automatically collapse/expand in content wordpress (single.php)?

dompdf and img tag, image wont show

Statement that checks whether a URL contains a particular path?

Symfony/Form add attribute based on the data

How can I make good efficent AJAX live forms with just jQuery and

curl returning 301 error after migrating to https

Destroy session upon refresh

how to see if database exists with PDO [duplicate]

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'column_name' in Laravel

Composer Warning: openssl extension is missing. How to enable in WAMP

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

PHP Get value from JSON [duplicate]

About Contact Privacy policy Terms and conditions