• 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 to create a video stream from a single dynamic image in PHP

Limit WooCommerce products in cart only from one custom taxonomy

Changing font color in javascript

How to create a individual template for page or post in custom plugin?

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

Facebook PHP SDK - will not logout properly

correct PHP headers for pdf file download

Display the default discounted price and percentage on Woocommerce products

How to add a custom field to all Woocommerce attribute terms using add_action

How to change the app environment at run time?

Don't show recurring price for WooCommerce subscriptions worth 0$

Redirect to previous page with php

Check if my GET request has Header: Token

Display the WooCommerce product price inside a custom function

Detect if PHP session exists

About Contact Privacy policy Terms and conditions