• 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

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Can we define variables in `.tpl` files?

PHP error: "The zip extension and unzip command are both missing, skipping."

WordPress + Nginx on non-standard port behind AWS ELB results in broken links

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

phpseclib 2.0 can not use Composer to create autoload

How to create a video stream from a single dynamic image in PHP

wordpress : How to specify the cause "This site can’t be reached"

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type

WHERE IN array binding in DB::raw laravel 5.4

How to debug in WooCommerce 3+

How to change HTML structure inside WP <head>

Laravel Factory not calling callback 'afterCreating'

CodeIgniter 4: Like and Dislike Functionality

php 7 php.ini upload_max_filesize not working

About Contact Privacy policy Terms and conditions