• 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

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

Laravel websockets AWS EC2 - Connection failed

Best way to scrolldown onpageload

How to get the survey List from surveygizmo API in the Postman?(Trial Version)

Update Order custom Field value with WooCommerce REST API

How to average columns of data from multiple, flat arrays?

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

Install mysql client in docker image

Add customer email and phone in "Order" column to admin orders list on Woocommerce

How to make Canonicals with PHP

Malformed MIME header error in Symfony 5.3

calling server using nusoap with complextype

Filter WooCommerce related products by Polylang language

How to add a sidebar to Woocommerce Shop Page?

woocommerce_wp_select options array from product attribute terms

About Contact Privacy policy Terms and conditions