1

I am working on Drupal Commerce website. Using Commerce Stock I am able to manage the inventory but on product details page I want to print the following.

Availability: In Stock

or

Availability: Out of Stock

Also if possible

Availability: Limited Stock

If I am displaying stock filed its showing number of items available in stock, which I don't want to display.

Is there any way in Drupal I can acheive this task?

2
  • how are you displaying your products? Views, node view modes, other?
    – oksana-c
    May 17, 2016 at 12:01
  • Are you working with Drupal 7 Commerce or Drupal 8 Commerce. If you know, please then tag your question with 7 or 8. Thank you. Nov 12, 2018 at 21:19

2 Answers 2

1

On Drupal 7.61 & Commerce Stock 7.x-2.3 I've solved it with hook_commerce_product_reference_default_delta_alter:

/**
 * Implements hook_commerce_product_reference_default_delta_alter().
*/
function test_module_commerce_product_reference_default_delta_alter(&$delta, $products) {

foreach ($products as $product) {
  if ($product->commerce_stock['und'][0]['value'] > 0){
    $product->commerce_stock['und'][0]['value'] = "On stock";
  }else {
    $product->commerce_stock['und'][0]['value'] = "Out of stock";
  }
 }
}
0

You can set these message in STOCK manage display of every product variation type. Store->Configuration->Product variation types->YOUR PRODUCT VARIATION TYPE->Manage display. Change label as above and change format as Show stock display as message .Finally change the message on settings on right side of field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.