• 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

Cant seem to get the Pagination to work on my WooCommerce REST API application?

Display a product custom field only in WooCommerce Admin single orders

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

Calculating Median of an array in PHP

Laravel csrf token mismatch for ajax POST Request

PHP AWS Cognito 'Error executing "SignUp" : ResourceNotFoundException : User pool client XXXX does not exist

oauth-private.key does not exist or is not readable

PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: no such host known

How do I enable error reporting in Laravel?

WHM Enabling mod_rewrite

Make Shipping Method fields Mandatory on Woocommerce checkout page

How to add a custom field to all Woocommerce attribute terms using add_action

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

Auto increment id JSON

CodeIgniter extend CI_URI undefined method

About Contact Privacy policy Terms and conditions