• 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

Losing session data after POST from third party website

Laravel csrf token mismatch for ajax POST Request

PHP cURL (SSL certificate problem: self signed certificate in certificate chain)

add " ? " in url via htaccess RewriteRule

How to pass data to all views in Laravel 5?

Comma separated list from array with "and" before last element

PHP array sort and remove duplicates by two field values

Custom post type single page not working

how to get the header value, if we don't know the value because the value is random from the server

Composer Warning: openssl extension is missing. How to enable in WAMP

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

Unable to create lockable file - Laravel 8 & PHP 8

how to remove white space in select 2

Filter WooCommerce products with post__in and additional meta queries

TesseractOCR not working for Laravel

About Contact Privacy policy Terms and conditions