• 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

I want to store data in new index as per my key in php [duplicate]

User pool client {id}does not exist

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

Log file is not being written in Laravel 5.5

json_encode turns array into an object

Dropzone: Submit both form data and dropzone at once

How can I convert from a{a{} b{}} to a[a[],b[]] using php preg_match?

PHP, how to convert Int value to Week days

Laravel Pagination links() not working

How to make Canonicals with PHP

PHP returning an error message and false

500 Internal Server Error on Ajax request. Not sure the origin of the problem

Convert regular text to array using notepad++

PHP Fatal error: Class not found - PHPUnit

Can I use a WooCommerce function without any WooCommerce page?

About Contact Privacy policy Terms and conditions