• 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

woocommerce change position of price

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

Where do I need to place a hook for phpunit?

Get orders by date and status woocommerce

PHP, how to convert Int value to Week days

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

Split a string array into pieces

Call authenticate manually in router middleware

Getting public posts of a random user from Facebook API

Hide email address with stars (*)

Laravel SQL query midnight time not showing

How to make autocomplete work in foreach php loop? (vscode, intellisense)

How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

Confirm Leave on External Links in Wordpress

About Contact Privacy policy Terms and conditions