• 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

Comma separated list from array with "and" before last element

How to reset Laravel AuthManager/guards in between API calls in tests?

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

Laravel Pagination links() not working

Send Outlook 2010 email using PHP

How to programmatically find public properties of a class from inside one of it's methods

How to average columns of data from multiple, flat arrays?

how to get the header value, if we don't know the value because the value is random from the server

Converting array to string and then back in PHP

Get WooCommerce products from specific category

Laravel print last executed SQL query with Query log

advanced custom fields wordpress custom class

Magento 2 - How to add new block to admin panel in product page?

CSS file not imported in laravel blade view

How to disable only_full_group_by option in Laravel

About Contact Privacy policy Terms and conditions