• 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 MODIFY a Google Docs document via API using search-and-replace?

XSS attack still works despite htmlspecialchars() doing its work

Use Python plotly chart in PHP

Laravel Schedule not sending email

zsh: command not found: php

Wordpress wpdb->delete issue

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

How to make autocomplete work in foreach php loop? (vscode, intellisense)

Warning: A non-numeric value encountered

woocommerce change position of price

Nginx disallowing execution of PHP in uploads directory with Magento

Laravel set default language not working

Laravel database insert with combining array and string

Declaration of OMDb::query(string $statement) must be compatible with PDO::query

PHPMetrics option --excluded-dirs="myfolder" : myfolder dir is not excluded within docker

About Contact Privacy policy Terms and conditions