• 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

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

Laravel 8 factory state afterCreating

Must be of the type array, null given,

How to run or debug php on Visual Studio Code (VSCode)

What's the net::ERR_HTTP2_PROTOCOL_ERROR about?

wordpress function breaks wp-admin

(Laravel) How to delete multiple models including optional relationships?

How to add a heading in between checkout fields of WooCommerce

Correct way to use LIKE '%{$var}%' with prepared statements?

Having issue with matching rows in the database using PDO

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

Timber: Single post pagination does not work (wp_link_pages)

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

hidden INPUT value not available in $_POST

How to add a heading in between checkout fields of WooCommerce

About Contact Privacy policy Terms and conditions