• 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

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

Calculating Median of an array in PHP

How can I make this nested location configuration use the correct path to call a php program?

Using array_intersect on a multi-dimensional array

json_encode turns array into an object

Add restriction to WooCommerce coupons by allowed user ID

How to skip cart page on woocomerce for certain products only?

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

How to test a php login connected to a mysql db through xampp?

How can i hide dt if dd got empty value

Issue with laravel eloquent model property

Laravel s3 upload file with metadata using pre-signed url

PHP | "The requested PHP extension bcmath is missing from your system."

Get sum of arrays inside array

Get WooCommerce products from specific category

About Contact Privacy policy Terms and conditions