• 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

Transpose and flatten two-dimensional indexed array where rows may not be of equal length

How to retrieve Active Directory group policy maximum password age using LDAP

PHPS source file - 403 Forbidden You don't have permission to access this resource

How to disable only_full_group_by option in Laravel

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

How to Install Composer Require doctrine/dbal

Reorder attribute dropdown terms in Woocommerce single variable products

PHP web3 ERC20 token function call

PHP echo values of all sub keys [duplicate]

Create a zip file and download it

Lumen - Postgresql setup - Composer

how do i retrieve and display the alt text of an image in wordpress?

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

loop through an anchor id

Pass a select with mysqli_fetch_row to a table

About Contact Privacy policy Terms and conditions