• 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

Add custom text under order details on WooCommerce My account view order pages

Make Shipping Method fields Mandatory on Woocommerce checkout page

Trying to iterate over a mongodb cursor twice - failing

Laravel Route issues with Route order in web.php

woocommerce_wp_select options array from product attribute terms

Yii Ajax Submit button

How to add a heading in between checkout fields of WooCommerce

Add restriction to WooCommerce coupons by allowed user ID

Woocommerce redirect after add-to-cart error

Remove product downloads section in woocommerce email notifications

Symfony run hint kernel.secret parameter not found

Form repeater send wrong data with last element in Laravel

Use Python plotly chart in PHP

renameColumn migration fails for existing column with columns does not exist error

Distribute array row data to make multiple new rows

About Contact Privacy policy Terms and conditions