claudiosanches / woocommerce-payment-discounts

Adds discounts for specific payment methods in WooCommerce.
http://wordpress.org/extend/plugins/woocommerce-payment-discounts/
31 stars 10 forks source link

Discount not delete when another payment select #40

Open PuDesign opened 7 years ago

PuDesign commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

Bproductiv commented 7 years ago

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 commented 7 years ago

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

Bproductiv commented 7 years ago

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 commented 7 years ago

didn't work for me.

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

digitalheldin commented 6 years ago

is there a solution now?

amddiego commented 6 years ago

Hi.. what´s the solution? thank you

Bproductiv commented 6 years ago

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

stefanweindl commented 6 years ago

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

Federicost commented 6 years ago

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!