• 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

Timber: Single post pagination does not work (wp_link_pages)

Additional price based on cart item count in WooCommerce

How to implement placeholder in a php file for moodle plugin?

PHP array, move keys and values to new array, but mix it up

correct PHP headers for pdf file download

Chunk and transpose a flat array into rows with a specific number of columns

PHP Deprecated issue when running artisan command

Login if user is active using Laravel Breeze

Mysqli multi query error

php script to delete files older than 24 hrs, deletes all files

Doctrine ORM: Excluding Records Based on Values of Nested Relationships

Dynamic dropdown Ajax PHP request

PHP and WebView - Cookie doesn't are the same

Shopify password update using Shopify API

How can I make a full text index of the column?

About Contact Privacy policy Terms and conditions