Created
January 14, 2014 18:03
-
-
Save jasonruyle/8422776 to your computer and use it in GitHub Desktop.
Drupal Commerce Rules: Loop through Commerce Line Items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use the code inside rule conditions with a Custom PHP code | |
// FIELD_MACHINE_NAME example: field_product_free_shipping | |
global $user; | |
$commerce_order = commerce_cart_order_load($user->uid); | |
$line_items = $commerce_order->commerce_line_items['und']; | |
foreach ($line_items as $lid) { | |
$line_item = commerce_line_item_load($lid['line_item_id']); | |
if ( isset($line_item->commerce_product)) { | |
$pid = $line_item->commerce_product['und'][0]['product_id']; | |
$product = commerce_product_load($pid); | |
$FIELD_MACHINE_NAME = render($product->FIELD_MACHINE_NAME['und'][0]['value']); | |
if ($FIELD_MACHINE_NAME == '1') { | |
return TRUE; | |
} | |
} | |
} | |
return FALSE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment