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

Discount not delete when another payment select #40

Open
PuDesign opened this issue Aug 25, 2017 · 13 comments
Open

Discount not delete when another payment select #40

PuDesign opened this issue Aug 25, 2017 · 13 comments

Comments

@PuDesign
Copy link

Hi,

i have a problem, i have just one payment method with a discount. When the user select another payment method (without discount) the old discount won't delete.

is there an solution?

best Frank

@toto72
Copy link

toto72 commented Sep 22, 2017

HI,

I have the same problem. Two payment methods, bank transfer and another one, I want a discount only for bacs, when the user isinto the checkout page, if he switchs from bacs to the other methos, the copoun is removed but the total is not updated.

Can you help to fix?

Best
Sal

@wagnerlinaldi
Copy link

Olá,
Estou com o mesmo problema do toto72, ao escolher o BACS (TED/DOC) ele aplica o cupom, mas ao excluir o cupom, escolhendo outras formas de pagamento, o desconto permanece no carrinho (o valor não muda). Minha versão do Woocommerce é 3.2.0

@nicoworq
Copy link

Bom Día !

I´m having the same problem as described here.

Woocommerce 3.2.3 , and using the last version of this plugin.

When i select the payment method with the discount, the coupon gets added, but the total price doesn´t change.

I have to reload the page to make it work.

The same thing happens when i select the payment without the discount. The coupon gets deleted but no changes in price.

I´m using the Official MercadoLibre Plugin, Versión 3.0.3 .

Thanks !!

@claudiosanches
Copy link
Owner

Not fixed yet, I'm trying to have free time to work in a new version of this plugin,

@Bproductiv
Copy link

Bproductiv commented Nov 29, 2017

Hi @claudiosanches ,
i found a way to achieve the removal of the generated coupon when a user select another payment gateway.
File:includes/class-wc-payment-discounts-apply-discount.php
function:add_discount
line 131.
You just have to put an else on this if
if ( isset( $settings[ WC()->session->chosen_payment_method ]['amount'] ) ) {
and to put this:

else{
			$methods = WC()->payment_gateways->payment_gateways();
			$gateway = $methods[ WC()->session->chosen_payment_method ];
			$coupon  = WC_Payment_Discounts_Coupons::get_coupon( $gateway->id, array( 'amount' => $amount ) );
			$this->remove_payment_coupons( $cart, $coupon->get_code() );
			wc_add_notice('Désolé par de réduction sur ce mode de paiement','warning');
		}

Work for me, hope it could help.
Great plugin, thanks

@PuDesign
Copy link
Author

Hi @Bproductiv ,
are your sure with line 131? How did you add this there?

@Bproductiv
Copy link

Bproductiv commented Nov 30, 2017

Oops it's not the good php file sorry, it's class-wc-payment-discounts-apply-discount.php (i update the first post).

This the complete function

/**
	 * Add discount.
	 *
	 * @param WC_Cart $cart Cart object.
	 */
	public function add_discount( $cart ) {
		if ( is_admin() && ! defined( 'DOING_AJAX' ) || is_cart() ) {
			return;
		}

		// Gets the settings.
		$settings = get_option( 'woocommerce_payment_discounts' );

		// Always set coupons calculation as enabled.
		add_filter( 'woocommerce_coupons_enabled', '__return_true' );

		if ( isset( $settings[ WC()->session->chosen_payment_method ]['amount'] ) ) {
			// Gets the gateway discount.
			$amount = $settings[ WC()->session->chosen_payment_method ]['amount'];

			if ( apply_filters( 'wc_payment_discounts_apply_discount', 0 < $amount, $cart ) ) {
				// Gets the gateway data.
				$methods = WC()->payment_gateways->payment_gateways();
				$gateway = $methods[ WC()->session->chosen_payment_method ];
				$coupon  = WC_Payment_Discounts_Coupons::get_coupon( $gateway->id, array( 'amount' => $amount ) );

				// Remove other coupons and apply method coupon.
				$this->remove_payment_coupons( $cart, $coupon->get_code() );
				if ( ! $cart->has_discount( $coupon->get_code() ) ) {
					$cart->add_discount( $coupon->get_code() );
				}
			} else {
				$this->remove_payment_coupons( $cart );
			}

		}else{
			$methods = WC()->payment_gateways->payment_gateways();
			$gateway = $methods[ WC()->session->chosen_payment_method ];
			$coupon  = WC_Payment_Discounts_Coupons::get_coupon( $gateway->id, array( 'amount' => $amount ) );
			$this->remove_payment_coupons( $cart, $coupon->get_code() );
			wc_add_notice('Désolé par de réduction sur ce mode de paiement','notice');
		}
	}

@PuDesign
Copy link
Author

PuDesign commented Dec 5, 2017

didn't work for me.

when i change the payment back, the discount still leave there

@digitalheldin
Copy link

is there a solution now?

@amddiego
Copy link

Hi.. what´s the solution? thank you

@Bproductiv
Copy link

@stefanweindl
Copy link

Hi @claudiosanches, can you estimate when you will implement ajax function in checkout to solve this issue? Thanks!

@Federicost
Copy link

Hi. I have the same problem. I have 2 payments methods. Bank Transfer and MercadoPago. I want to apply a discount only to Bank Transfer. When I click on the Bank Transfer method it will applied the discount, but if I change to MercadoPago the discount is not remove. Please I need help!

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

10 participants