• 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

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

XAMPP keeps showing Dashboard/Welcome Page instead of the Configuration Page

Add restriction to WooCommerce coupons by allowed user ID

How to properly set "0000-00-00 00:00:00" as a DateTime in PHP

How to read laravel_session cookies saved in cookie memory of browser in client side?

301 Redirect to remove query string on homepage only

Webscraping Symfony/Panther: Can't get HTML

How to get the survey List from surveygizmo API in the Postman?(Trial Version)

javascript html popup window

How to disable widget block editor of WordPress?

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

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

Cannot connect to own websocket server when on secured domain

Unable to uninstall brew php from homebrew

Artisan, creating tables in database

About Contact Privacy policy Terms and conditions