• 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

PHP array, move keys and values to new array, but mix it up

Respond with status code 401 on authentication failure using Laravel and Passport?

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

How can I make a full text index of the column?

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

Get all WooCommerce products within own plugin

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

MySQL - Connection failed: No route to host

Autoloading classes in PHPUnit using Composer and autoload.php

json_encode turns array into an object

Adding the custom page with add_menu_page function on Wordpress

Nginx RTMP not recording

Woocommerce Checkout - Add conditional field required if one field is filled

PHP: How to raise number to (tiny) fractional exponent?

How to get array values using foreach in laravel

About Contact Privacy policy Terms and conditions