• 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

Eloquent insert id with sequence next value

Edit product hook WooCommerce

Laravel post contact form giving me error 419

Split comma separated value from table column into rows using mysql?

How can I access an array/object?

How to identify whether webp image is static or animated?

With doctrine ODM, can I embed many subdocuments in a main document?

PHPMetrics option --excluded-dirs="myfolder" : myfolder dir is not excluded within docker

Custom post type single page not working

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

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

httpd.conf on Windows: can't locate API model structure `php8_module`

PHP error: "The zip extension and unzip command are both missing, skipping."

WordPress - Dynamically add user ID to the end of a URL

PHP -> Next nearest date defined by array of days in week

About Contact Privacy policy Terms and conditions