• 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

Remove categories with all childs derived from parent category

best way to store error messages in Laravel (session or variable)

How to auto populate preferredCountries from intl-tel-input with db output

MongoDB Duplicate Documents even after adding unique key

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

Create a zip file and download it

hidden INPUT value not available in $_POST

How to validate Envato Purchase Code in PHP

The sum of the user's points

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

Insert database rows from columns of data from associative array of indexed arrays

Google Calendar API batch request PHP

How to add a heading in between checkout fields of WooCommerce

json_encode turns array into an object

About Contact Privacy policy Terms and conditions