• 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

Display a product custom field only in WooCommerce Admin single orders

Yii Ajax Submit button

Add rows to Single product Additional information table in WooCommerce 3.6

How to pass security cloudflare server with php curl

WordPress ACFNotice: get_field() - We've detected one or more calls to retrieve ACF field values before ACF has been initialized

TesseractOCR not working for Laravel

Add New Parameter to Existing URL using htaccess

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

What will the best solution for this multiple optional filter?

Confirm Leave on External Links in Wordpress

Get all WooCommerce products within own plugin

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

Array to string conversion

How to create a scheduler application in php

About Contact Privacy policy Terms and conditions