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?

  • how are you displaying your products? Views, node view modes, other? – oksana-c May 17 '16 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. – therobyouknow Nov 12 '18 at 21:19
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, privacy policy and cookie policy

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