diff --git a/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php b/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php index d79d522..255f792 100644 --- a/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php +++ b/admin/class-paypal-for-woocommerce-multi-account-management-admin-express-checkout.php @@ -255,7 +255,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew } else { $this->map_item_with_account[$product_id]['is_taxable'] = false; } - if ($product->needs_shipping()) { + if ($product->needs_shipping() && apply_filters('angelleye_multi_account_need_shipping', true, $order_id, $product_id)) { $this->map_item_with_account[$product_id]['needs_shipping'] = true; $this->angelleye_needs_shipping = $this->angelleye_needs_shipping + 1; } else { @@ -356,7 +356,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew } else { $this->map_item_with_account[$product_id]['is_taxable'] = false; } - if ($product->needs_shipping()) { + if ($product->needs_shipping() && apply_filters('angelleye_multi_account_need_shipping', true, '', $product_id)) { $this->map_item_with_account[$product_id]['needs_shipping'] = true; $this->angelleye_needs_shipping = $this->angelleye_needs_shipping + 1; } else { @@ -1439,4 +1439,62 @@ public function own_woocommerce_create_refund($refund, $args) { remove_action( 'woocommerce_order_partially_refunded', array( 'WC_Emails', 'send_transactional_email' ) ); } } + + public function own_angelleye_multi_account_need_shipping($bool, $order_id = '', $current_product_id = '') { + $is_required = 0; + $is_not_required = 0; + if( !empty($order_id) ) { + $order = wc_get_order($order_id); + foreach ($order->get_items() as $cart_item_key => $values) { + $line_item = $values->get_data(); + $product = $order->get_product_from_item($values); + $product_exists = is_object( $product ); + if($product_exists == false) { + $product_id = apply_filters('angelleye_multi_account_get_product_id', '', $cart_item_key); + if(!empty($product_id)) { + $product = wc_get_product($product_id); + } else { + continue; + } + } + $product_id = $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id(); + $_no_shipping_required = get_post_meta($product_id, '_no_shipping_required', true); + if( $_no_shipping_required == 'yes' ) { + $is_not_required = $is_not_required + 1; + } elseif($product->needs_shipping()) { + $is_required = $is_required + 1; + } else { + $is_not_required = $is_not_required + 1; + } + } + } else { + if (isset(WC()->cart) && sizeof(WC()->cart->get_cart()) > 0) { + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { + $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); + $product = wc_get_product($product_id); + $_no_shipping_required = get_post_meta($product_id, '_no_shipping_required', true); + if( $_no_shipping_required == 'yes' ) { + $is_not_required = $is_not_required + 1; + } elseif($product->needs_shipping()) { + $is_required = $is_required + 1; + } else { + $is_not_required = $is_not_required + 1; + } + } + } + } + + if( !empty($current_product_id) ) { + $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); + $_no_shipping_required = get_post_meta($current_product_id, '_no_shipping_required', true); + if( $_no_shipping_required == 'yes' ) { + if($is_required > 0) { + return false; + } + } + } + + return $bool; + + } } \ No newline at end of file diff --git a/includes/class-paypal-for-woocommerce-multi-account-management.php b/includes/class-paypal-for-woocommerce-multi-account-management.php index 37de7a7..fb24200 100644 --- a/includes/class-paypal-for-woocommerce-multi-account-management.php +++ b/includes/class-paypal-for-woocommerce-multi-account-management.php @@ -180,6 +180,7 @@ private function define_admin_hooks() { $this->loader->add_action('woocommerce_order_refunded', $express_checkout, 'own_woocommerce_order_fully_refunded', 10, 2); //$this->loader->add_filter('woocommerce_paypal_args', $paypal, 'angelleye_woocommerce_paypal_args', 10, 2); $this->loader->add_action('woocommerce_create_refund', $express_checkout, 'own_woocommerce_create_refund', 10, 2); + $this->loader->add_filter('angelleye_multi_account_need_shipping', $express_checkout, 'own_angelleye_multi_account_need_shipping', 10, 3); }