Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider product level no shipping required option, PFWMA-110 #49

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

}
}
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