• 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

301 Redirect to remove query string on homepage only

Cant seem to get the Pagination to work on my WooCommerce REST API application?

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

XDebug not working in VScode for php debugging

How to send upload image through email

Override default Auth routes in Laravel 7

WooCommerce - unset "<product> removed notice…" on cart page

Find out the name of the last script that included the current one

Filter WooCommerce products with post__in and additional meta queries

Star rating with half star support

how to pass row id in href of a tag in codeigniter controller?

Can I use a WooCommerce function without any WooCommerce page?

How to get AJAX to post on second page?

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

Transpose multidimensional array and join values with commas

About Contact Privacy policy Terms and conditions