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

filter errado: woocommerce_get_customer_payment_tokens #83

Open
gopaulo opened this issue Apr 21, 2023 · 0 comments
Open

filter errado: woocommerce_get_customer_payment_tokens #83

gopaulo opened this issue Apr 21, 2023 · 0 comments

Comments

@gopaulo
Copy link

gopaulo commented Apr 21, 2023

no arquivo iugu-woocommerce.php linha 101 a function woocommerce_get_customer_payment_tokens sobreescreve os $tokens e anula todos os outros gateways de pagamento.

isso acaba tornando o iugu como metodo de pagamento exclusivo e cria incompatibilidade com outros plugins de pagamento.

O correto seria array_push ou um array_merge nos $tokens, dessa forma evitando apagar os $tokens carregados em outros plugins que tenham usado o mesmo filter "woocommerce_get_customer_payment_tokens"


function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
	if (WC()->session != null &&
	    !WC()->session->get('in_woocommerce_get_customer_payment_tokens', false)) {
		WC()->session->set('in_woocommerce_get_customer_payment_tokens', true);
		try {
			$api = new WC_Iugu_API(null, 'credit-card');
			if (strlen(get_user_meta(get_current_user_id(), '_iugu_customer_id', true)) > 0) {
				$api->get_customer_id();
				**$tokens = $api->get_payment_methods();**
			}
			if (is_array($tokens) && count($tokens) == 0) {
				$customer_id_iugu = $api->get_customer_id();
				if ($customer_id_iugu) {
					$payment_methods_iugu = $api->get_iugu_customer_payment_methods($customer_id_iugu);
					if (is_array($payment_methods_iugu) && count($payment_methods_iugu) > 0) {
						foreach ($payment_methods_iugu as $token_info) {
							if (isset($token_info['item_type']) && $token_info['item_type'] == 'credit_card') {
								$api->set_wc_payment_method($token_info, false, $customer_id_iugu);
							}
						}
						**$tokens = WC_Iugu_API::get_payment_methods();**
					}
				}
			}
		} finally {
			WC()->session->set('in_woocommerce_get_customer_payment_tokens', false);
		}
	}
	return $tokens;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant