• 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

How to reset Laravel AuthManager/guards in between API calls in tests?

Creating command to backup MySql database in Laravel

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

Statement that checks whether a URL contains a particular path?

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

Not able to access model in the controller mautic

PHP-Sort array based on another array?

Statement that checks whether a URL contains a particular path?

How to change 'users' auth table and use another instead Laravel

Cut an arabic string

PHP Deprecated issue when running artisan command

find in set in laravel ? example

Update Order custom Field value with WooCommerce REST API

Losing session data after POST from third party website

PHP Print to Network Printer

About Contact Privacy policy Terms and conditions