Vote up!
Vote down!

Multitple Countries shipping Rule

I had created shipping rules.How can i put multiple countires when i use condition
Commerce Shipping Address

Country Code

If i want multiple countries need to check means shall i put comma separated or in new line

Asked by: ajaichandran
on September 24, 2013

1 Answer

Vote up!
Vote down!

I dont think this is possible with Dcommerce.

I achieved this adding another option in

function commerce_order_address_comparison_operator_options_list() {
return array(
'equals' => t('equals'),
'begins with' => t('begins with'),
'contains' => t('contains'),
'is one of' => t('is one of'),/*Newly added*/

and added a new switch case condition here for that

function commerce_order_rules_compare_address($order, $address_field, $component, $operator, $value) {
list($field_name, $address_field_name) = explode('|', $address_field);

// If we actually received a valid order...
if (!empty($order)) {
$wrapper = entity_metadata_wrapper('commerce_order', $order);

// And if we can actually find the requested address data...
if (!empty($wrapper->{$field_name}) && !empty($wrapper->{$field_name}->{$address_field_name})) {
$address = $wrapper->{$field_name}->{$address_field_name}->value();

// Make a comparison based on the operator.
switch ($operator) {
case 'equals':
return $address[$component] == $value;
case 'begins with':
return strpos($address[$component], $value) === 0;
case 'contains':
return strpos($address[$component], $value) !== FALSE;
case 'is one of':
$list = preg_split('/[\n\r]+/', $value);

if( in_array( $address[$component] ,$list ))
return true;
return false;

return FALSE;

This changes worked fro me

Answer by: ajaichandran
Posted: Sep 26, 2013