• 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 do I pass the dynamic output of a php variable or php function to a CSS variable?

array_map triple dimensional array [duplicate]

json_encode turns array into an object

Set quantity minimum, maximum and step at product level in Woocommerce

Additional price based on cart item count in WooCommerce

How to pass data to all views in Laravel 5?

Update Total in checkout of Woocommerce with Ajax Request

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

PHPExcel How to set conditional formatting to change cell background color based on cells values

I'm trying to write a clean url for my website using the $_SERVER['REQUEST_URI'] in php

Why isn't my PHP exception working?

Can I write PHP code across multiple lines per statement?

PHP Deprecated issue when running artisan command

How do I do HTTP basic authentication using Guzzle?

How to disable only_full_group_by option in Laravel

About Contact Privacy policy Terms and conditions