• 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

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

How to create a scheduler application in php

Remove product downloads section in woocommerce email notifications

How can i hide dt if dd got empty value

"Mixed content blocked" when running an HTTP AJAX operation in an HTTPS page

Shortcode or PHP inside a shortcode in Wordpress

php echo remove slashes from url [duplicate]

Form repeater send wrong data with last element in Laravel

Put content of wordpress page inside div

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

str_replace or preg_replace random number from string

Laravel relationship belongsToMany with composite primary keys

Laravel 5 session not persisting after user is logged in

php curl_exec() Connection refused when retrieving a remote image

PHP, how to convert Int value to Week days

About Contact Privacy policy Terms and conditions