• 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

woocommerce change position of price

Open a popup box after receiving result from ajax

Show rotation of tweets using current day of month

Remove categories with all childs derived from parent category

Implode array with array of glue strings

Custom add to cart button URL for specific product in WooCommerce?

Search for array row with specific column value and return another value from qualifying row

mysql_result is defined but mysql_free_result warns it expected a resource

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

(Laravel) How to delete multiple models including optional relationships?

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Laravel no logout option from menu after successfull login

api response laravel doesn't show

wp_remote_get() not passing authentication

Limit WooCommerce products in cart only from one custom taxonomy

About Contact Privacy policy Terms and conditions