• 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

Sagepay Error The Vendor failed to provide a RedirectionURL

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

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

Laravel s3 upload file with metadata using pre-signed url

Redis Command To Sort Keys

HTML + PHP + PHPMAILER

Composer fails with kylekatarnls/update-helper on new homestead

How to to send mail using gmail in Laravel?

Webscraping Symfony/Panther: Can't get HTML

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

Merge key and value of array index [duplicate]

Confirm Leave on External Links in Wordpress

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

Appending data to an anchor tag

Getting public posts of a random user from Facebook API

About Contact Privacy policy Terms and conditions