• 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

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

display WooCommerce “Add to cart” button with short-code [add_to_cart ] dynamically

Batch request Google Calendar php API

how to check version of codeigniter framework?

How to skip cart page on woocomerce for certain products only?

WordPress Security Standards want me to escape my html, but how to do it correctly?

How to modify CSS in a specific page of the WP admin dashboard (backend)

Apply filter array/return terms

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

merging two arrays with specified index

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

How to fix bootstrap multiselect search data using ajax

correct PHP headers for pdf file download

How to unlink image from folder?

Laravel/docker-compose/redis - Class 'Redis' not found

About Contact Privacy policy Terms and conditions