• 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

file_put_content...fail to open stream:Permission denied in Laravel 5

javascript html popup window

How to loop a tree array with unknown depth and get array blocks?

Why rand() every time I refresh the page?

CodeIgniter 4: Like and Dislike Functionality

Extract string between first whitespace and last whitespace in php

Laravel 5.1 how to use {{ old('') }} helper on blade file for radio inputs

Unit (real unit test) of test laravel relationship

Creating a config file in PHP

PHP Print to Network Printer

Add and update products to session cart in Laravel

Wordpress wpdb->delete issue

Move a child array to parent array and change parent/child name

Warning: A non-numeric value encountered

How to remove index.php and index from the URL using htaccess | PHP

About Contact Privacy policy Terms and conditions