• 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

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

How do I do HTTP basic authentication using Guzzle?

PHP array sort and remove duplicates by two field values

Laravel Sanctum CSRF not authenticating

Woocommerce redirect after add-to-cart error

PHP Discord OAUTH2 code sample not working

Add rows to Single product Additional information table in WooCommerce 3.6

Change the alert text on add to cart action without selected variation in Woocommerce

Phalcon: setStatusCode returns empty response

Adding hreflang tags automatically in WordPress subdirectory multisite

how to youtube api data to print in toolset metabox using a button click before save-post

Can't find vendor/autoload.php for Ratchet

Laravel Nova, route not found

PHP Include for HTML?

How to properly start Laravel 8 with Bootstrap & authentication

About Contact Privacy policy Terms and conditions