• Resolved rajeshsingh520

    (@rajeshsingh520)


    Hi,

    We have 2 currency USD and INR

    we are applying a virtual coupon discount, discount is 50% of the cart subtotal

    it work properly when we are in base currency, but when we switch to other currency it goes wrong

    our code takes the subtotal (which is already converted to other currency) and then applies that amount as discount (but here it goes wrong) you plugin applies the conversion again on this amount so its gives wrong result

    We want to know how to disable the currency conversion on our coupon

    here is our coupon code you can try it on your end

    
    
    class virtual_coupon_test{
    	function __construct(){
    		add_action('woocommerce_before_calculate_totals', array($this,'applyDiscountCode'));
    		add_action('woocommerce_after_calculate_totals', array($this,'applyDiscountCode'));
    		add_filter('woocommerce_get_shop_coupon_data', array($this, 'addDiscountCouponData'),10,3);
    	}
    
    	function applyDiscountCode(WC_Cart $cart){
            $cart->applied_coupons[] = "pisol-cdrw-discount:test";
        }
    
    	function addDiscountCouponData($false, $data, $coupon){
    		
            if(!function_exists('WC') || !isset(WC()->cart) ) return false;
    
    		$coupon_id = "pisol-cdrw-discount:test";
    
    		$subtotal = WC()->cart->get_subtotal();
    
    		$off = $subtotal * 50 / 100;
    
            $coupon->set_discount_type('fixed_cart');
            $coupon->set_description( 'Test coupon' );
            $coupon->set_amount(abs($off));
                    
            return $coupon;
                
        }
    
    }
    
    new virtual_coupon_test();
    
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • kimvt1991

    (@kimvt1991)

    Hello,
    Please try using the wmc_revert_price($price) function to revert $subtotal back to the base currency before calculating the discount amount.
    Best regards

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    Thanks for such a fast reply

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disable currency conversion on Virtual coupon’ is closed to new replies.