• 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

api response laravel doesn't show

How to fix bootstrap multiselect search data using ajax

Laravel - How to properly generate unique slugs from article titles?

Can't find vendor/autoload.php for Ratchet

How do I call Validator from a namespace with an already existing Validator class

Yii2 redirecting to previous page after login

"cannot list resources" error from WooCommerce REST API

Refresh specific HTML content that retrieves data from MySQL

I cannot create a auto generated date time in mysql workbench

Show date difference as "20" instead of "20 years ago"

Get sum of arrays inside array

Symfony there are no commands defined in the "make" namespace

Alert message after submitting form in PHP

Convert string to lowercase AND then convert it to its original form in PHP, is it possible?

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

About Contact Privacy policy Terms and conditions