• 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

"There is no active transaction" when refreshing database in Laravel 8.0 test

Statement that checks whether a URL contains a particular path?

Trying to iterate over a mongodb cursor twice - failing

how do i retrieve and display the alt text of an image in wordpress?

Edit XML in HTML form and submit to self

Unable to match results of php hash_hmac() and coldfusion hmac()

Update Order custom Field value with WooCommerce REST API

Cut an arabic string

Using spatie/media-library, how to rename a collection of uploaded files?

How to add automatically collapse/expand in content wordpress (single.php)?

Query Optimization, changing the queries in the loop into a single processing query

Show Custom Data in Woocommerce Order Details Admin Area

Using PHP to connect to a remote MSSQL database

Send same name multiple checkbox values via ajax

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

About Contact Privacy policy Terms and conditions