• 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 prevent phpmailer sending embedded image as an attachment on Gmail?

CodeIgniter 4: Like and Dislike Functionality

Filter array by skipping every nth element from the end

CodeIgniter force_download is not working

How to load Codeigniter 4 lang file into an array variable

Display the default discounted price and percentage on Woocommerce products

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

Laravel Schedule not sending email

add_action() function in wordpress not working [duplicate]

Error converting docx to pdf using Unoconv

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

Vimeo API: how to save a vimeo into a subfolder?

How to change HTML structure inside WP <head>

How to trim a video by 4 fragments to 4 seconds using the PHP-FFMpeg?

How to skip cart page on woocomerce for certain products only?

About Contact Privacy policy Terms and conditions