• 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

What is the difference between client-side and server-side programming?

How do I remove this delivery notification from here?

How to extract price from given url using Xpath?

Can't find vendor/autoload.php for Ratchet

How to disable widget block editor of WordPress?

How to get array values using foreach in laravel

Android Volley getParams() method not getting called for JsonObjectRequest

Laravel query builder binding parameters more than once

PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT "INOUT")

oauth-private.key does not exist or is not readable

Put content of wordpress page inside div

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

Woocommerce redirect after add-to-cart error

How do I truncate a decimal in PHP?

Batch request Google Calendar php API

About Contact Privacy policy Terms and conditions