• 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 implement placeholder in a php file for moodle plugin?

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given [duplicate]

How to extract price from given url using Xpath?

codeigniter 4 running error first time with xampp

Using array_intersect on a multi-dimensional array

Call to a member function givePermissionTo() on null

PHP 8 - libxml_disable_entity_loader() has been deprecated. How do I replace the functionality it provides?

How to get the total hour from starting time to end time in php

Combining a describing and one array with data

Clear javascript source cache laravel 5.8

Handling expired token in Laravel

CodeIgniter 3 is generating a session file on each request, why?

I need to link Google Sheet with my Laravel

Last order would be re-order in wooCommerce. How is it possible?

unable to load your default controller on Codeigniter

About Contact Privacy policy Terms and conditions