• 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

str_replace or preg_replace random number from string

how can I set a session variable in Drupal 8 and get it in a php script?

Laravel Gates using model and returns "Using $this when not in object context" Line 28 of AzureUser model

dockerizing Laravel + vue

image source not readable

Last order would be re-order in wooCommerce. How is it possible?

Sum column values from multiple arrays

How to show a popup modal in codeIgniter?

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

Show date difference as "20" instead of "20 years ago"

Inserting Country Selection into MySQL PHP [duplicate]

Store / Website Column in Magento 2 Admin Grid - Custom Module

Laravel 5.2: Unable to locate factory with name [default]

How to install php yaml on CentOs?

WordPress + Nginx on non-standard port behind AWS ELB results in broken links

About Contact Privacy policy Terms and conditions