• 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

PHP to search within txt file and echo the whole line

args[max_input] woocommerce if statement confused

browsersync doesn't work with XAMPP

WordPress Security Standards want me to escape my html, but how to do it correctly?

Detect emoticons in string

Creating live search with AJAX and CodeIgniter

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

Edit product hook WooCommerce

Custom add to cart button URL for specific product in WooCommerce?

wp_remote_get() not passing authentication

Could not decode a text frame as UTF-8.

Post Form Data To phpmyadmin Database

Add customer email and phone in "Order" column to admin orders list on Woocommerce

How to install ZeroMQ for PHP on an Alpine Linux container?

Change user role if checkout custom checkbox is checked in WooCommerce

About Contact Privacy policy Terms and conditions