• 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

Laravel print last executed SQL query with Query log

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

Laravel query builder binding parameters more than once

Install mysql client in docker image

Insert And Retrieve Data in MySQL with $.post Noob Question

How to pass data to all views in Laravel 5?

Warning: A non-numeric value encountered

OAuth2 Token PHP

WordPress ACFNotice: get_field() - We've detected one or more calls to retrieve ACF field values before ACF has been initialized

Adding custom body class to the custom archive pages

calling server using nusoap with complextype

How to put php code inside opening and closing shortcodes

how to redirect the user back to desired URL after login page in PHP?

Make Shipping Method fields Mandatory on Woocommerce checkout page

Applying programmatically a coupon to an Order in WooCommerce3

About Contact Privacy policy Terms and conditions