Gizmodo
Gizmodo

Reputation: 3242

PHP Comparison Inversion

Following code is from an excommerce shipping module:

      if (!IS_ADMIN_FLAG) {
        global $cart;

        $chk_products_in_cart = 0;
        $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '12');
        $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '22');

        // do not show florida 18 and new york 43
        $chk_delivery_zone = $order->delivery['zone_id'];
        $chk_states = '18, 43';
        $arr1 = explode(", ", $chk_states);
        $arr2 = explode(", ", $chk_delivery_zone);
        $donotshow_state = array_intersect($arr1, $arr2);
        if ((int)$donotshow_state && $chk_products_in_cart > 0) {
          $this->enabled = false;
        }
      }

Above code checks if the items in the shopping cart are product id's 12 or 22 along with the shipping zone/state id 18 or 43. If both those are true, it disables ($this->enabled = false;).

If products 12 or 22 are in the cart and shipping zone is 18 or 43, DISABLE

I want to modify the zone portion of this to be:

If products 12 or 22 are in the cart and shipping zone is not 43, DISABLE

Upvotes: 1

Views: 45

Answers (1)

Nikos M.
Nikos M.

Reputation: 8345

Use this:

if (!IS_ADMIN_FLAG) {
        global $cart;

        $chk_products_in_cart = 0;
        $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '12');
        $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '22');

        // disable if not 43 and $chk_products_in_cart > 0
        $arr2 = explode(", ", $order->delivery['zone_id']);
        if (!in_array('43', $arr2) && $chk_products_in_cart > 0) {
          $this->enabled = false;
        }
      }

Upvotes: 1

Related Questions