• 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

PHP usort() order in case of equality

Detect a fetch request in PHP

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

Xdebug in Laravel is not working with VSCode

Upgrade PHP on AWS Linux

GA4 custom event from server side, can someone tell me how i can do the following code in php?

Combine multiple columns into an array as one of the key in a results set

disable two buttons after clicking another button

Laravel - How to properly generate unique slugs from article titles?

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

nginx err_connection_refused, can anyone help me?

best way to store error messages in Laravel (session or variable)

Confirm Leave on External Links in Wordpress

How to add class name to an existing tag in php

find in set in laravel ? example

About Contact Privacy policy Terms and conditions