Skip to content

Instantly share code, notes, and snippets.

@jasonruyle
Created January 14, 2014 18:03
Show Gist options
  • Select an option

  • Save jasonruyle/8422776 to your computer and use it in GitHub Desktop.

Select an option

Save jasonruyle/8422776 to your computer and use it in GitHub Desktop.

Revisions

  1. jasonruyle created this gist Jan 14, 2014.
    18 changes: 18 additions & 0 deletions commerce_rules_line_item_loop.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?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;