• 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

woocommerce change position of price

How to fix 'Data has already been sent to output, unable to output PDF file' in MPDF

PHP DOTENV unable to load env vars

Select option menu read from database and use it's values

Laravel Unknown Column 'updated_at'

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

With doctrine ODM, can I embed many subdocuments in a main document?

jQuery Ajax Post with data

woocommerce get_order_report_data to show order_item_id

Add customer email and phone in "Order" column to admin orders list on Woocommerce

PHP and WebView - Cookie doesn't are the same

Magento Installation SQLSTATE[HY000] [2002] No such file or directory error

Unable to uninstall brew php from homebrew

Why does using salted hash on python and php give me different results?

Filter WooCommerce products with post__in and additional meta queries

About Contact Privacy policy Terms and conditions