Skip to content

Commit

Permalink
Merge pull request #49 from angelleye/PFWMA-110
Browse files Browse the repository at this point in the history
consider product level no shipping required option, PFWMA-110
  • Loading branch information
deepakmaurya authored May 4, 2020
2 parents 7b1ba48 + 70326ee commit 8946d7d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,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 {
Expand Down Expand Up @@ -377,7 +377,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 {
Expand Down Expand Up @@ -1480,4 +1480,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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);


}
Expand Down

0 comments on commit 8946d7d

Please sign in to comment.