• 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

Adding Multiple Custom Post Types in Wordpress

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

Target Individual Form Instance/Counter Inside A PHP While Loop

PHP only Hit Counter?

PHP block shortcut in Visual Studio Code

Why is this PHP array not the same?

Sort a multidimensional array by integer inside of a string value which is two levels down

How to set time with DateTime modify?

how to sort by a custom appended relation to model

Install mysql client in docker image

Access relation of pivot table in Laravel

Can I use a WooCommerce function without any WooCommerce page?

Display a success custom notice after Placing an Order in WooCommerce

Must be of the type array, null given,

How to install php_imagick on wamp64

About Contact Privacy policy Terms and conditions