woocommerce-payment-discounts icon indicating copy to clipboard operation
woocommerce-payment-discounts copied to clipboard

Discount not delete when another payment select

Open PuDesign opened this issue 8 years ago • 13 comments

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

PuDesign avatar Aug 25 '17 07:08 PuDesign

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

toto72 avatar Sep 22 '17 12:09 toto72

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

wagnerlinaldi avatar Oct 11 '17 16:10 wagnerlinaldi

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

nicoworq avatar Nov 10 '17 15:11 nicoworq

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

claudiosanches avatar Nov 10 '17 16:11 claudiosanches

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

Bproductiv avatar Nov 29 '17 22:11 Bproductiv

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

PuDesign avatar Nov 30 '17 14:11 PuDesign

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');
		}
	}

Bproductiv avatar Nov 30 '17 15:11 Bproductiv

didn't work for me.

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

PuDesign avatar Dec 05 '17 13:12 PuDesign

is there a solution now?

digitalheldin avatar Mar 15 '18 14:03 digitalheldin

Hi.. what´s the solution? thank you

amddiego avatar Jul 16 '18 18:07 amddiego

I use this plugin : https://fr.wordpress.org/plugins/woo-payment-discounts/

Bproductiv avatar Jul 17 '18 08:07 Bproductiv

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

stefanweindl avatar Aug 16 '18 06:08 stefanweindl

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!

Federicost avatar Nov 27 '18 14:11 Federicost