• 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

Best way to scrolldown onpageload

How avoid Moved Permanently The document has moved here

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

PHP: convert all UTF-8 characters to HTML entities

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

MOODLE: What does it mean to aggregate h5p assets?

Target Laravelista is not instantiable

How to change product Image when variables are selected in Shop and Archive Pages?

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

Target Individual Form Instance/Counter Inside A PHP While Loop

selected value from the listbox in php

Star rating with half star support

Reading input in php from terminal

Show only featured products in Woocommerce shop page

What's the net::ERR_HTTP2_PROTOCOL_ERROR about?

About Contact Privacy policy Terms and conditions