Skip to content

Instantly share code, notes, and snippets.

@denvit
Last active November 12, 2018 13:17
Show Gist options
  • Select an option

  • Save denvit/a99db3ceebdae5d7953fdab26132aad9 to your computer and use it in GitHub Desktop.

Select an option

Save denvit/a99db3ceebdae5d7953fdab26132aad9 to your computer and use it in GitHub Desktop.
Drupal 7 - Hook alters stock display message. Formatter for Stock must be set as "Unformatted" on Product > Manage display.
/**
* Implements hook_commerce_product_reference_default_delta_alter().
*/
function test_module_commerce_product_reference_default_delta_alter(&$delta, $products) {
$test = 123;
foreach ($products as $product) {
if ($product->commerce_stock['und'][0]['value'] > 0){
$products[1]->commerce_stock['und'][0]['value'] = "On stock";
}else {
$product->commerce_stock['und'][0]['value'] = "Out of stock";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment