• 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

Match single unknown parameter php (Morse-code Regex)

Execute only one time and then wait set period of time before executing again

Display specific shipping method if woocommerce product has specific acf field value

Fatal error: Trait 'LaminasDbAdapterLaminasDbAdapterAdapterInterface' not found in /var/www/vendor/laminas/laminas-db/src/Adapter/Adapter.php

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

Prestashop cUrl Login

Filter array by skipping every nth element from the end

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

Using array_intersect on a multi-dimensional array

Call authenticate manually in router middleware

Filter WooCommerce products with post__in and additional meta queries

shell errors running php exec

(Laravel) How to delete multiple models including optional relationships?

loop through an anchor id

laravel 5.6 bulk inserting json data

About Contact Privacy policy Terms and conditions