• 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 redirect after add-to-cart error

Why isn't my PHP exception working?

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

Using PHP to connect to a remote MSSQL database

file_put_content...fail to open stream:Permission denied in Laravel 5

Get image type from base64 encoded src string

Display the WooCommerce product price inside a custom function

Custom add to cart button URL for specific product in WooCommerce?

Laravel Excel::store file empty after stored

Limit WooCommerce products in cart only from one custom taxonomy

How to create custom authentication in laravel 8?

Timber: Single post pagination does not work (wp_link_pages)

Facebook PHP SDK - will not logout properly

mysql_result is defined but mysql_free_result warns it expected a resource

About Contact Privacy policy Terms and conditions