• 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

Check if my GET request has Header: Token

Any AWS EB Laravel route getting 404 Not Found nginx/1.16.1

Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?

How can I easily switch between PHP versions on Mac OSX?

How to put php code inside opening and closing shortcodes

How to run a shell as root from php (apache)

PHP, how to convert Int value to Week days

GRPC installed successfully on ubuntu but php is looking for it in another folder

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

Dynamic dropdown Ajax PHP request

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type

Add rows to Single product Additional information table in WooCommerce 3.6

Message: Set sys_temp_dir in your php.ini after installed composer

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

Handle error for duplicate entries - PHP/MySQL

About Contact Privacy policy Terms and conditions