• 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 remove %20 in the url in php

PHP: Insert marker every 3 iterations

PHP: Print caught exception like Xdebug

Normalize DateInterval in PHP

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

Laravel 8 factory state afterCreating

How can i hide dt if dd got empty value

Add custom text under order details on WooCommerce My account view order pages

TesseractOCR not working for Laravel

How to generate QR CODE for dynamic generating link and logo using Simple QrCode in laravel?

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Laravel Excel::store file empty after stored

sort() not affecting original array while inside foreach loop

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Make Shipping Method fields Mandatory on Woocommerce checkout page

About Contact Privacy policy Terms and conditions