From 8fc699af31d098f6a0e8b12e65b4c6753910dad6 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Mon, 19 Oct 2020 13:25:54 +0530 Subject: [PATCH 1/2] Add condition for only compare if checkout field is not empty, PFWMA-192 --- ...ount-management-admin-express-checkout.php | 146 +++++++++--------- 1 file changed, 76 insertions(+), 70 deletions(-) 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 6f46781..71b3d1b 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 @@ -183,39 +183,46 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew continue; } } - + $checkout_custom_fields = angelleye_display_checkout_custom_field(); if (!empty($checkout_custom_fields)) { foreach ($checkout_custom_fields as $field_key => $field_data) { $custom_field_value = get_post_meta($value->ID, $field_key, true); - if (!empty($order_id) && $order_id > 0) { - $field_order_value = get_post_meta($order_id, $field_key, true); - if (!empty($field_order_value) && $field_order_value == $custom_field_value) { - $passed_rules['custom_fields'] = true; - } else { - $passed_rules['custom_fields'] = ''; - break; - } - } else { - $post_checkout_data = WC()->session->get('post_data'); - if (!empty($post_checkout_data)) { - if (!empty($post_checkout_data[$field_key]) && $post_checkout_data[$field_key] == $custom_field_value) { + if (!empty($custom_field_value)) { + if (!empty($order_id) && $order_id > 0) { + $field_order_value = get_post_meta($order_id, $field_key, true); + if (empty($field_order_value)) { + $passed_rules['custom_fields'] = true; + } elseif (!empty($field_order_value) && $field_order_value == $custom_field_value) { $passed_rules['custom_fields'] = true; } else { $passed_rules['custom_fields'] = ''; break; } - } + } else { + $post_checkout_data = WC()->session->get('post_data'); + if (!empty($post_checkout_data)) { + if (empty($post_checkout_data[$field_key])) { + $passed_rules['custom_fields'] = true; + } elseif (!empty($post_checkout_data[$field_key]) && $post_checkout_data[$field_key] == $custom_field_value) { + $passed_rules['custom_fields'] = true; + } else { + $passed_rules['custom_fields'] = ''; + break; + } + } + } + } else { + $passed_rules['custom_fields'] = true; } } - } else { $passed_rules['custom_fields'] = true; } if (empty($passed_rules['custom_fields'])) { continue; } - + $buyer_countries = get_post_meta($value->ID, 'buyer_countries', true); if (!empty($buyer_countries)) { foreach ($buyer_countries as $buyer_countries_key => $buyer_countries_value) { @@ -238,7 +245,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if (!empty($billing_country) && $billing_country == $buyer_countries_value) { $passed_rules['buyer_countries'] = true; break; - } elseif(!empty($shipping_country) && $shipping_country == $buyer_countries_value) { + } elseif (!empty($shipping_country) && $shipping_country == $buyer_countries_value) { $passed_rules['buyer_countries'] = true; break; } @@ -246,7 +253,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if (!empty($post_checkout_data['billing_country']) && $post_checkout_data['billing_country'] == $buyer_countries_value) { $passed_rules['buyer_countries'] = true; break; - } elseif(!empty($post_checkout_data['shipping_country']) && $post_checkout_data['shipping_country'] == $buyer_countries_value) { + } elseif (!empty($post_checkout_data['shipping_country']) && $post_checkout_data['shipping_country'] == $buyer_countries_value) { $passed_rules['buyer_countries'] = true; break; } @@ -270,11 +277,10 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if (!empty($billing_postcode) && $billing_postcode == $postcode_value) { $passed_rules['postcode'] = true; break; - } elseif(!empty($shipping_postcode) && $shipping_postcode == $postcode_value) { + } elseif (!empty($shipping_postcode) && $shipping_postcode == $postcode_value) { $passed_rules['postcode'] = true; break; } - } else { $post_checkout_data = WC()->session->get('post_data'); if (empty($post_checkout_data)) { @@ -283,7 +289,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if (!empty($billing_postcode) && $billing_postcode == $postcode_value) { $passed_rules['postcode'] = true; break; - } elseif(!empty($shipping_postcode) && $shipping_postcode == $postcode_value) { + } elseif (!empty($shipping_postcode) && $shipping_postcode == $postcode_value) { $passed_rules['postcode'] = true; break; } @@ -291,7 +297,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew if (!empty($post_checkout_data['billing_postcode']) && $post_checkout_data['billing_postcode'] == $postcode_value) { $passed_rules['postcode'] = true; break; - } elseif(!empty($post_checkout_data['shipping_postcode']) && $post_checkout_data['shipping_postcode'] == $postcode_value) { + } elseif (!empty($post_checkout_data['shipping_postcode']) && $post_checkout_data['shipping_postcode'] == $postcode_value) { $passed_rules['postcode'] = true; break; } @@ -327,7 +333,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew $order = wc_get_order($order_id); foreach ($order->get_items() as $cart_item_key => $values) { $line_item = $values->get_data(); - $product = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_product_from_item( $values ) : $values->get_product(); + $product = version_compare(WC_VERSION, '3.0', '<') ? $order->get_product_from_item($values) : $values->get_product(); $product_exists = is_object($product); if ($product_exists == false) { $product_id = apply_filters('angelleye_multi_account_get_product_id', '', $cart_item_key); @@ -358,7 +364,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew $this->map_item_with_account[$product_id]['is_discountable'] = true; $this->angelleye_is_discountable = $this->angelleye_is_discountable + 1; $discount_amount = $line_item['subtotal'] - $line_item['total']; - if($discount_amount > 0) { + if ($discount_amount > 0) { $this->map_item_with_account[$product_id]['discount'] = $discount_amount; } } else { @@ -487,7 +493,7 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew $this->map_item_with_account[$product_id]['is_discountable'] = true; $this->angelleye_is_discountable = $this->angelleye_is_discountable + 1; $discount_amount = $cart_item['line_subtotal'] - $cart_item['line_total']; - if($discount_amount > 0) { + if ($discount_amount > 0) { $this->map_item_with_account[$product_id]['discount'] = $cart_item['line_subtotal'] - $cart_item['line_total']; } } else { @@ -622,7 +628,7 @@ public function angelleye_paypal_for_woocommerce_multi_account_api_paypal_expres $payment_action = array('set_express_checkout', 'get_express_checkout_details', 'do_express_checkout_payment'); if (!empty($_GET['pp_action']) && ( in_array($_GET['pp_action'], $payment_action))) { $angelleye_payment_load_balancer = get_option('angelleye_payment_load_balancer', ''); - if($angelleye_payment_load_balancer != '') { + if ($angelleye_payment_load_balancer != '') { return $this->angelleye_get_account_for_ec_payment_load_balancer($gateways, $gateway_setting, $order_id, $request); } else { return $this->angelleye_get_account_for_ec_parallel_payments($gateways, $gateway_setting, $order_id, $request); @@ -722,15 +728,15 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o if (!empty($this->map_item_with_account)) { $packages = WC()->shipping()->get_packages(); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); - if(!empty($packages) && !empty($chosen_shipping_methods) && count($packages) > 1) { - foreach ( $packages as $package_key => $package ) { - if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) { - $shipping_rate = $package['rates'][ $chosen_shipping_methods[ $package_key ] ]; + if (!empty($packages) && !empty($chosen_shipping_methods) && count($packages) > 1) { + foreach ($packages as $package_key => $package) { + if (isset($chosen_shipping_methods[$package_key], $package['rates'][$chosen_shipping_methods[$package_key]])) { + $shipping_rate = $package['rates'][$chosen_shipping_methods[$package_key]]; foreach ($package['contents'] as $key => $value) { $product_id = isset($value['product_id']) ? $value['product_id'] : false; } - if($product_id) { - if(isset($this->map_item_with_account[$product_id])) { + if ($product_id) { + if (isset($this->map_item_with_account[$product_id])) { $this->map_item_with_account[$product_id]['shipping_cost'] = AngellEYE_Gateway_Paypal::number_format($shipping_rate->cost); } } @@ -760,7 +766,7 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o $this->final_order_grand_total = $order->get_total(); foreach ($order->get_items() as $cart_item_key => $cart_item) { $is_mismatch = false; - $product = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_product_from_item( $cart_item ) : $cart_item->get_product(); + $product = version_compare(WC_VERSION, '3.0', '<') ? $order->get_product_from_item($cart_item) : $cart_item->get_product(); $product_exists = is_object($product); if ($product_exists == false) { $product_id = apply_filters('angelleye_multi_account_get_product_id', '', $cart_item_key); @@ -801,27 +807,27 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o $final_total = AngellEYE_Gateway_Paypal::number_format($final_total - $product_commission, $order); $default_item_total = $default_item_total + $product_commission; - if( $this->global_ec_include_tax_shipping_in_commission == 'on' ) { - if( $taxamt > 0 ) { + if ($this->global_ec_include_tax_shipping_in_commission == 'on') { + if ($taxamt > 0) { $tax_commission = AngellEYE_Gateway_Paypal::number_format($taxamt / 100 * $this->map_item_with_account[$product_id]['ec_site_owner_commission'], 2); $default_final_total = $default_final_total + $tax_commission; $final_total = AngellEYE_Gateway_Paypal::number_format($final_total - $tax_commission); $taxamt = AngellEYE_Gateway_Paypal::number_format($taxamt - $tax_commission); $default_item_total = $default_item_total + $tax_commission; } - if( $shippingamt > 0) { + if ($shippingamt > 0) { $shippingamt_commission = AngellEYE_Gateway_Paypal::number_format($shippingamt / 100 * $this->map_item_with_account[$product_id]['ec_site_owner_commission'], 2); $default_final_total = $default_final_total + $shippingamt_commission; $final_total = AngellEYE_Gateway_Paypal::number_format($final_total - $shippingamt_commission); $shippingamt = AngellEYE_Gateway_Paypal::number_format($shippingamt - $shippingamt_commission); $default_item_total = $default_item_total + $shippingamt_commission; } - $sub_total_commission = AngellEYE_Gateway_Paypal::number_format( $product_commission + $tax_commission + $shippingamt_commission ); + $sub_total_commission = AngellEYE_Gateway_Paypal::number_format($product_commission + $tax_commission + $shippingamt_commission); } else { $sub_total_commission = $product_commission; } - - + + $Item = array( 'name' => $this->map_item_with_account[$product_id]['ec_site_owner_commission_label'], 'desc' => $line_item['name'], @@ -1040,27 +1046,27 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o $final_total = AngellEYE_Gateway_Paypal::number_format($final_total - $product_commission); $item_total = AngellEYE_Gateway_Paypal::number_format($item_total - $product_commission); $default_item_total = $default_item_total + $product_commission; - - if( $this->global_ec_include_tax_shipping_in_commission == 'on' ) { - if( $taxamt > 0 ) { + + if ($this->global_ec_include_tax_shipping_in_commission == 'on') { + if ($taxamt > 0) { $tax_commission = AngellEYE_Gateway_Paypal::number_format($taxamt / 100 * $this->map_item_with_account[$product_id]['ec_site_owner_commission'], 2); $default_final_total = $default_final_total + $tax_commission; $final_total = AngellEYE_Gateway_Paypal::number_format($final_total - $tax_commission); $taxamt = AngellEYE_Gateway_Paypal::number_format($taxamt - $tax_commission); $default_item_total = $default_item_total + $tax_commission; } - if( $shippingamt > 0) { + if ($shippingamt > 0) { $shippingamt_commission = AngellEYE_Gateway_Paypal::number_format($shippingamt / 100 * $this->map_item_with_account[$product_id]['ec_site_owner_commission'], 2); $default_final_total = $default_final_total + $shippingamt_commission; $final_total = AngellEYE_Gateway_Paypal::number_format($final_total - $shippingamt_commission); $shippingamt = AngellEYE_Gateway_Paypal::number_format($shippingamt - $shippingamt_commission); $default_item_total = $default_item_total + $shippingamt_commission; } - $sub_total_commission = AngellEYE_Gateway_Paypal::number_format( $product_commission + $tax_commission + $shippingamt_commission ); + $sub_total_commission = AngellEYE_Gateway_Paypal::number_format($product_commission + $tax_commission + $shippingamt_commission); } else { $sub_total_commission = $product_commission; } - + $Item = array( 'name' => $this->map_item_with_account[$product_id]['ec_site_owner_commission_label'], 'desc' => $line_item['name'], @@ -1493,7 +1499,7 @@ public function angelleye_get_line_item_from_cart($product_id, $values) { } public function angelleye_get_line_item_from_order($order, $values) { - $product = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_product_from_item( $values ) : $values->get_product(); + $product = version_compare(WC_VERSION, '3.0', '<') ? $order->get_product_from_item($values) : $values->get_product(); $product_sku = null; if (is_object($product)) { $product_sku = $product->get_sku(); @@ -1607,9 +1613,9 @@ public function own_angelleye_express_checkout_order_data($paypal_response, $ord for ($payment = 0; $payment <= 10; $payment++) { if (!empty($paypal_response['PAYMENTINFO_' . $payment . '_TRANSACTIONID'])) { $order->add_order_note(sprintf(__('PayPal Express payment Transaction ID: %s', 'paypal-for-woocommerce-multi-account-management'), isset($paypal_response['PAYMENTINFO_' . $payment . '_TRANSACTIONID']) ? $paypal_response['PAYMENTINFO_' . $payment . '_TRANSACTIONID'] : '')); - } elseif(!empty($paypal_response['PAYMENTINFO_' . $payment . '_ERRORCODE'])) { + } elseif (!empty($paypal_response['PAYMENTINFO_' . $payment . '_ERRORCODE'])) { $long_message = !empty($paypal_response['PAYMENTINFO_' . $payment . '_LONGMESSAGE']) ? $paypal_response['PAYMENTINFO_' . $payment . '_LONGMESSAGE'] : ''; - if( !empty($long_message) ) { + if (!empty($long_message)) { $order->add_order_note($long_message); } } else { @@ -1623,12 +1629,12 @@ public function own_angelleye_express_checkout_order_data($paypal_response, $ord if (!empty($paypal_response['PAYMENTINFO_' . $transaction_map . '_PAYMENTREQUESTID'])) { $PAYMENTREQUESTID_array = $paypal_response['PAYMENTINFO_' . $transaction_map . '_PAYMENTREQUESTID']; $request_order_item_id = explode('-', $PAYMENTREQUESTID_array); - if( !empty($request_order_item_id[0]) && $ec_parallel_data['order_item_id'] == $request_order_item_id[0]) { - if( !empty($paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID'])) { + if (!empty($request_order_item_id[0]) && $ec_parallel_data['order_item_id'] == $request_order_item_id[0]) { + if (!empty($paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID'])) { $ec_parallel_data_map[$ec_parallel_data['product_id']]['transaction_id'] = $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID']; $unique_transaction_data[] = $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID']; wc_update_order_item_meta($ec_parallel_data['order_item_id'], '_transaction_id', $paypal_response['PAYMENTINFO_' . $transaction_map . '_TRANSACTIONID']); - } elseif(!empty($paypal_response['PAYMENTINFO_' . $payment . '_ERRORCODE'])) { + } elseif (!empty($paypal_response['PAYMENTINFO_' . $payment . '_ERRORCODE'])) { wc_update_order_item_meta($ec_parallel_data['order_item_id'], 'Payment Status', __('Not Paid', 'paypal-for-woocommerce-multi-account-management')); } } @@ -1636,7 +1642,7 @@ public function own_angelleye_express_checkout_order_data($paypal_response, $ord } } $total_paypal_transaction = $total_account + 1; - if( !empty($ec_parallel_data_map)) { + if (!empty($ec_parallel_data_map)) { for ($transaction = 0; $transaction <= $total_paypal_transaction; $transaction++) { if (isset($paypal_response['PAYMENTINFO_' . $transaction . '_TRANSACTIONID']) && !empty($paypal_response['PAYMENTINFO_' . $transaction . '_TRANSACTIONID'])) { if (!in_array($paypal_response['PAYMENTINFO_' . $transaction . '_TRANSACTIONID'], $unique_transaction_data)) { @@ -1645,7 +1651,6 @@ public function own_angelleye_express_checkout_order_data($paypal_response, $ord } } } - } if (!empty($ec_parallel_data_map)) { update_post_meta($order_id, '_angelleye_multi_account_ec_parallel_data_map', $ec_parallel_data_map); @@ -1696,7 +1701,7 @@ public function own_angelleye_is_express_checkout_parallel_payment_handle($bool, $refund_error_message_pre = __('We can not refund this order as the Express Checkout API keys are missing! Please go to multi-account setup and add API key to process the refund', 'paypal-for-woocommerce-multi-account-management'); $refund_error_message_after = array(); $angelleye_multi_account_ec_parallel_data_map = get_post_meta($order_id, '_angelleye_multi_account_ec_parallel_data_map', true); - if( !empty($angelleye_multi_account_ec_parallel_data_map) ) { + if (!empty($angelleye_multi_account_ec_parallel_data_map)) { foreach ($angelleye_multi_account_ec_parallel_data_map as $key => $value) { if (!empty($value['product_id']) && isset($value['is_api_set']) && apply_filters('angelleye_pfwma_is_api_set', $value['is_api_set'], $value) === false) { $product = wc_get_product($value['product_id']); @@ -1873,7 +1878,7 @@ public function own_angelleye_multi_account_need_shipping($bool, $order_id = '', $order = wc_get_order($order_id); foreach ($order->get_items() as $cart_item_key => $values) { $line_item = $values->get_data(); - $product = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_product_from_item( $values ) : $values->get_product(); + $product = version_compare(WC_VERSION, '3.0', '<') ? $order->get_product_from_item($values) : $values->get_product(); $product_exists = is_object($product); if ($product_exists == false) { $product_id = apply_filters('angelleye_multi_account_get_product_id', '', $cart_item_key); @@ -1936,14 +1941,14 @@ public function angelleye_get_account_for_ec_payment_load_balancer($gateways, $g $session_key = 'angelleye_payment_load_balancer_ec_email'; $session_key_account = 'angelleye_payment_load_balancer_ec_account'; } - $found_email = WC()->session->get( $session_key ); - if( empty($found_email) ) { + $found_email = WC()->session->get($session_key); + if (empty($found_email)) { $found_email = ''; $express_checkout_accounts = get_option($option_key); - if(!empty($express_checkout_accounts)) { + if (!empty($express_checkout_accounts)) { foreach ($express_checkout_accounts as $key => $account) { - if(empty($account['is_used'])) { - if ( $key != 'default' && false === get_post_status( $key ) ) { + if (empty($account['is_used'])) { + if ($key != 'default' && false === get_post_status($key)) { unset($express_checkout_accounts[$key]); } else { $found_email = $account['email']; @@ -1957,13 +1962,13 @@ public function angelleye_get_account_for_ec_payment_load_balancer($gateways, $g } } } - if($found_account == false) { + if ($found_account == false) { foreach ($express_checkout_accounts as $key => $account) { $account['is_used'] = ''; $express_checkout_accounts[$key] = $account; } foreach ($express_checkout_accounts as $key => $account) { - if ( $key != 'default' && false === get_post_status( $key ) ) { + if ($key != 'default' && false === get_post_status($key)) { unset($express_checkout_accounts[$key]); } else { $found_email = $account['email']; @@ -1980,11 +1985,11 @@ public function angelleye_get_account_for_ec_payment_load_balancer($gateways, $g } } - if( !empty($request)) { - if($found_email != 'default') { + if (!empty($request)) { + if ($found_email != 'default') { $request['Payments'][0]['sellerpaypalaccountid'] = $found_email; - if( !empty($order_id)) { - $angelleye_payment_load_balancer_account = WC()->session->get( $session_key_account ); + if (!empty($order_id)) { + $angelleye_payment_load_balancer_account = WC()->session->get($session_key_account); update_post_meta($order_id, '_angelleye_payment_load_balancer_account', $angelleye_payment_load_balancer_account); } } @@ -2006,18 +2011,19 @@ public function own_angelleye_is_express_checkout_payment_load_balancer_handle($ $refund_error_message_pre = __('We can not refund this order as the Express Checkout API keys are missing! Please go to multi-account setup and add API key to process the refund', 'paypal-for-woocommerce-multi-account-management'); $angelleye_payment_load_balancer_account = get_post_meta($order_id, '_angelleye_payment_load_balancer_account', true); if (!empty($angelleye_payment_load_balancer_account)) { - if( !empty($angelleye_payment_load_balancer_account['is_api_set']) && apply_filters('angelleye_pfwma_is_api_set', $angelleye_payment_load_balancer_account['is_api_set'], $angelleye_payment_load_balancer_account) === true) { + if (!empty($angelleye_payment_load_balancer_account['is_api_set']) && apply_filters('angelleye_pfwma_is_api_set', $angelleye_payment_load_balancer_account['is_api_set'], $angelleye_payment_load_balancer_account) === true) { $_transaction_id = get_post_meta($order_id, '_transaction_id', true); $angelleye_payment_load_balancer_account['transaction_id'] = $_transaction_id; $this->angelleye_express_checkout_load_paypal($angelleye_payment_load_balancer_account, $gateway, $order_id); return true; } else { - return new WP_Error('invalid_refund', $refund_error_message_pre); + return new WP_Error('invalid_refund', $refund_error_message_pre); } } return $bool; } catch (Exception $ex) { - + } } -} \ No newline at end of file + +} From 2f1b53df08a82c1761816b2ca194ce44c123f73f Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Mon, 19 Oct 2020 14:36:10 +0530 Subject: [PATCH 2/2] Add condition for only compare if checkout field is not empty, PFWMA-192 --- ...ccount-management-admin-paypal-payflow.php | 85 ++++++++++--------- ...count-management-admin-paypal-standard.php | 22 +++-- 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-payflow.php b/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-payflow.php index 30836d3..3df03f6 100644 --- a/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-payflow.php +++ b/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-payflow.php @@ -155,19 +155,25 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga continue; } } - + $checkout_custom_fields = angelleye_display_checkout_custom_field(); if (!empty($checkout_custom_fields)) { foreach ($checkout_custom_fields as $field_key => $field_data) { $custom_field_value = get_post_meta($value->ID, $field_key, true); - if (!empty($order_id) && $order_id > 0) { - $field_order_value = get_post_meta($order_id, $field_key, true); - if (!empty($field_order_value) && $field_order_value == $custom_field_value) { - $passed_rules['custom_fields'] = true; - } else { - $passed_rules['custom_fields'] = ''; - break; + if (!empty($custom_field_value)) { + if (!empty($order_id) && $order_id > 0) { + $field_order_value = get_post_meta($order_id, $field_key, true); + if (empty($field_order_value)) { + $passed_rules['custom_fields'] = true; + } elseif (!empty($field_order_value) && $field_order_value == $custom_field_value) { + $passed_rules['custom_fields'] = true; + } else { + $passed_rules['custom_fields'] = ''; + break; + } } + } else { + $passed_rules['custom_fields'] = true; } } } else { @@ -176,7 +182,7 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga if (empty($passed_rules['custom_fields'])) { continue; } - + // Base Country $buyer_countries = get_post_meta($value->ID, 'buyer_countries', true); if (!empty($buyer_countries)) { @@ -188,7 +194,7 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga $shipping_country = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_country : $order->get_shipping_country(); if (!empty($billing_country) && $billing_country == $buyer_countries_value) { $passed_rules['buyer_countries'] = true; - } elseif(!empty($shipping_country) && $shipping_country == $buyer_countries_value) { + } elseif (!empty($shipping_country) && $shipping_country == $buyer_countries_value) { $passed_rules['buyer_countries'] = true; } } @@ -215,7 +221,7 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga if (!empty($billing_postcode) && $billing_postcode == $postcode_value) { $passed_rules['postcode'] = true; break; - } elseif(!empty($shipping_postcode) && $shipping_postcode == $postcode_value) { + } elseif (!empty($shipping_postcode) && $shipping_postcode == $postcode_value) { $passed_rules['postcode'] = true; break; } @@ -253,20 +259,20 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga } } } - + if (isset(WC()->cart) && WC()->cart->is_empty()) { foreach ($order->get_items() as $cart_item_key => $values) { - $product = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_product_from_item( $values ) : $values->get_product(); - $product_exists = is_object( $product ); - if($product_exists == false) { + $product = version_compare(WC_VERSION, '3.0', '<') ? $order->get_product_from_item($values) : $values->get_product(); + $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)) { + 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(); + } + $product_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id(); // Categories $woo_product_categories = wp_get_post_terms($product_id, apply_filters('angelleye_get_product_categories', array('product_cat')), array('fields' => 'ids')); $woo_product_categories = angelleye_get_product_cat($woo_product_categories); @@ -331,21 +337,21 @@ public function angelleye_get_multi_account_by_order_total_latest($gateways, $ga continue; } } - - $post_author_id = get_post_field( 'post_author', $product_id ); + + $post_author_id = get_post_field('post_author', $product_id); $woocommerce_paypal_express_api_user = get_post_meta($value->ID, 'woocommerce_paypal_express_api_user', true); if (!empty($woocommerce_paypal_express_api_user) && $woocommerce_paypal_express_api_user != 'all') { - if($post_author_id != $woocommerce_paypal_express_api_user) { - unset($result[$key]); + if ($post_author_id != $woocommerce_paypal_express_api_user) { + unset($result[$key]); unset($passed_rules); continue; } } - + $product_shipping_class = $product->get_shipping_class_id(); $shipping_class = get_post_meta($value->ID, 'shipping_class', true); - if (!empty($shipping_class) && $shipping_class != 'all' ) { - if($product_shipping_class != $shipping_class) { + if (!empty($shipping_class) && $shipping_class != 'all') { + if ($product_shipping_class != $shipping_class) { $cart_loop_not_pass = $cart_loop_not_pass + 1; continue; } @@ -519,7 +525,7 @@ public function angelleye_paypal_for_woocommerce_multi_account_api_paypal_payflo } } $angelleye_payment_load_balancer = get_option('angelleye_payment_load_balancer', ''); - if(!empty($angelleye_payment_load_balancer)) { + if (!empty($angelleye_payment_load_balancer)) { $microprocessing_value = $this->angelleye_get_account_for_payflow_payment_load_balancer($gateways, $gateway_setting, $order_id); } elseif ($this->is_angelleye_multi_account_used($order_id)) { $_multi_account_api_username = $this->angelleye_get_multi_account_api_user_name($order_id); @@ -632,8 +638,6 @@ public function angelleye_get_total($order_id) { return $cart_contents_total; } - - public function card_type_from_account_number($account_number) { $types = array( 'visa' => '/^4/', @@ -652,7 +656,7 @@ public function card_type_from_account_number($account_number) { } return null; } - + public function angelleye_get_account_for_payflow_payment_load_balancer($gateways, $gateway_setting, $order_id) { if (!isset($gateways->testmode)) { return; @@ -664,15 +668,15 @@ public function angelleye_get_account_for_payflow_payment_load_balancer($gateway } $is_account_found = false; $used_account = get_post_meta($order_id, '_multi_account_api_username_load_balancer', true); - if( $used_account == 'default' ) { + if ($used_account == 'default') { return; } - if( empty($used_account)) { + if (empty($used_account)) { $payflow_accounts = get_option($option_key); - if(!empty($payflow_accounts)) { + if (!empty($payflow_accounts)) { foreach ($payflow_accounts as $key => $account) { - if(empty($account['is_used'])) { - if ( $key != 'default' && false === get_post_status( $key ) ) { + if (empty($account['is_used'])) { + if ($key != 'default' && false === get_post_status($key)) { unset($payflow_accounts[$key]); } else { $account['is_used'] = 'yes'; @@ -685,13 +689,13 @@ public function angelleye_get_account_for_payflow_payment_load_balancer($gateway } } } - if($is_account_found == false) { + if ($is_account_found == false) { foreach ($payflow_accounts as $key => $account) { $account['is_used'] = ''; $payflow_accounts[$key] = $account; } foreach ($payflow_accounts as $key => $account) { - if ( $key != 'default' && false === get_post_status( $key ) ) { + if ($key != 'default' && false === get_post_status($key)) { unset($payflow_accounts[$key]); } else { $account['is_used'] = 'yes'; @@ -705,12 +709,12 @@ public function angelleye_get_account_for_payflow_payment_load_balancer($gateway } } } - if($used_account == 'default') { + if ($used_account == 'default') { return; } - if(!empty($used_account)) { + if (!empty($used_account)) { $post_meta = get_post_meta($used_account); - if( !empty($post_meta) ) { + if (!empty($post_meta)) { $microprocessing_value = array(); foreach ($post_meta as $key => $value) { $microprocessing_value[$key] = isset($value[0]) ? $value[0] : ''; @@ -719,4 +723,5 @@ public function angelleye_get_account_for_payflow_payment_load_balancer($gateway } } } -} \ No newline at end of file + +} diff --git a/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-standard.php b/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-standard.php index 94c3be3..7480918 100644 --- a/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-standard.php +++ b/admin/class-paypal-for-woocommerce-multi-account-management-admin-paypal-standard.php @@ -102,15 +102,21 @@ public function angelleye_woocommerce_paypal_args($request, $order) { if (!empty($checkout_custom_fields)) { foreach ($checkout_custom_fields as $field_key => $field_data) { $custom_field_value = get_post_meta($value->ID, $field_key, true); - if (!empty($order_id) && $order_id > 0) { - $field_order_value = get_post_meta($order_id, $field_key, true); - if (!empty($field_order_value) && $field_order_value == $custom_field_value) { - $passed_rules['custom_fields'] = true; - } else { - $passed_rules['custom_fields'] = ''; - break; + if (!empty($custom_field_value)) { + if (!empty($order_id) && $order_id > 0) { + $field_order_value = get_post_meta($order_id, $field_key, true); + if (empty($field_order_value)) { + $passed_rules['custom_fields'] = true; + } elseif (!empty($field_order_value) && $field_order_value == $custom_field_value) { + $passed_rules['custom_fields'] = true; + } else { + $passed_rules['custom_fields'] = ''; + break; + } } - } + } else { + $passed_rules['custom_fields'] = true; + } } } else { $passed_rules['custom_fields'] = true;