• 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

Laravel update hasMany relationship using saveMany

Show only featured products in Woocommerce shop page

PHP returning an error message and false

How to get multiple values with same key from an array PHP

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

Remove product downloads section in woocommerce email notifications

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

How to convert time from one timezone to another in PHP

How to add a custom field to all Woocommerce attribute terms using add_action

Pagekite error: FAIL: localhost:8080 is down

codeigniter 4 running error first time with xampp

Phalcon: setStatusCode returns empty response

Create a new line whenever an array value reaches more than 10 characters

PHP code for generating decent-looking coupon codes (mix of letters and numbers)

Laravel Get Days In Month From Month Number?

About Contact Privacy policy Terms and conditions