• 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 mysql + create a friend request system

ldap is missing from system when installing adldap2 in laravel

WooCommerce: Add/display Product or Variation custom field everywhere

Increase value by 1 on button click

Laravel lang slug in url

Adding reCAPTCHA v2 into my PHP file

Unable to create lockable file - Laravel 8 & PHP 8

Detect a fetch request in PHP

How to submit the custom form data in database in WordPress without plugin using ajax?

How to set time with DateTime modify?

Update Order custom Field value with WooCommerce REST API

Insert a DIV after the 6th product only once in WooCommerce category archives

Sentry on Symfony: how to exclude `NotFoundHttpException`

Server-sent events in PHP (without echo or print)

onKeyUp event calculation not working on the following rows from php generated forms except the first one

About Contact Privacy policy Terms and conditions