• 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

Natural ORDER in Laravel Eloquent ORM

How do I do HTTP basic authentication using Guzzle?

Mobile browsers are adding .html to filename on download

how to check version of codeigniter framework?

how to remove white space in select 2

Unable to create lockable file - Laravel 8 & PHP 8

PHP: remove filename from path

How to separate letters and digits from a string in php

WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

WAMP Virtual Host not working

ORA-12546: TNS:permission denied error connection to remote oracle server

How to access a var with "-" in PHP [duplicate]

Alert message after submitting form in PHP

How to convert a carbon into string, to take the date only?

disable two buttons after clicking another button

About Contact Privacy policy Terms and conditions