• 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

image source not readable

Center point of multiple gps coordinates with php

How to submit a form when page loads using JavaScript?

Applying programmatically a coupon to an Order in WooCommerce3

Minimum order amount except for specific shipping method in WooCommerce

PHP DOTENV unable to load env vars

Laravel s3 upload file with metadata using pre-signed url

User pool client {id}does not exist

Wordpress how to get the post thumbnail inside a figure tag

PHP Array split string and Integers

Insert multidimensional array to codeigniter cart

PHP Warning: Module already loaded in Unknown on line 0

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

Querying only one row from a one to many relationship laravel

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

About Contact Privacy policy Terms and conditions