• 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 validate form data in codeigniter 4

How to Make Laravel Eloquent "IN" Query?

Filter WooCommerce products with post__in and additional meta queries

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

Class AppHttpControllersUserController Does Not Exist

How to change product Image when variables are selected in Shop and Archive Pages?

Woocommerce Checkout - Add conditional field required if one field is filled

Add record for each array elements if missing in table

Unable to get password for the instance created from AMI

Laravel set default language not working

PHP returning an error message and false

Add 2 Webcam in one page with WebcamJS

how to use extended ASCII instead of unicode in PHP

Symfony 4: "Autowire: you should configure its value explicitly."

Limit WooCommerce products in cart only from one custom taxonomy

About Contact Privacy policy Terms and conditions