• 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 success custom notice after Placing an Order in WooCommerce

XAMPP/SQLSRV: Unable to find Sqlsrv in PHPINFO(); - errors coming from connection

Show date difference as "20" instead of "20 years ago"

How to disable widget block editor of WordPress?

Laravel relationship belongsToMany with composite primary keys

Saving Data from form to database using AngularJS and php

Is there a way to use Foundry Model for Authentification inside Functional Tests?

How can I format this number correctly using PHP?

"cannot list resources" error from WooCommerce REST API

How can I make this nested location configuration use the correct path to call a php program?

Having issue with matching rows in the database using PDO

Make Shipping Method fields Mandatory on Woocommerce checkout page

Woocommerce redirect after add-to-cart error

Display a product custom field only in WooCommerce Admin single orders

google content api for shopping

About Contact Privacy policy Terms and conditions