• 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

Statement that checks whether a URL contains a particular path?

Laravel websockets AWS EC2 - Connection failed

WooCommerce Subscriptions: Remove role on cancelled subscription

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

Pass an image through AJAX [duplicate]

how to pass row id in href of a tag in codeigniter controller?

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

Add record for each array elements if missing in table

Manage independently the decimal number of the price of each product [duplicate]

PHP drop down list using array's and foreach (else and for) code

Invalid value in field "itemtype" in Google Search Console

Don't show recurring price for WooCommerce subscriptions worth 0$

Error converting docx to pdf using Unoconv

Can't call javascript alert alertify library from PHP

Filter WooCommerce related products by Polylang language

About Contact Privacy policy Terms and conditions