• 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 install LDAP in Docker php-fpm alpine

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

Transform array, set each array element with parent key php

php echo remove slashes from url [duplicate]

Can I use a WooCommerce function without any WooCommerce page?

How to programmatically find public properties of a class from inside one of it's methods

Laravel Multi-language routes without prefix

Display specific shipping method if woocommerce product has specific acf field value

virtctl works when executed via command line but not from php exec()

How to use PHPCBF to fix one issue at a time?

Convert date and time to Jalali in Laravel

MySQL - Connection failed: No route to host

Can we define variables in `.tpl` files?

How to write PHP in XSLT

Sliders in Laravel

About Contact Privacy policy Terms and conditions