Repository Forums Support WooCommerce Extended Coupon Features PRO Not working correctly since Woo v4 Reply To: Not working correctly since Woo v4

#15327
Phil Whitwell
Participant

I found this code which is setting the total to £0

// Must be AFTER hook of Auto Coupon (5) but BEFORE WC_Cart_Session::set_session (10)
WJECF()->safe_add_action( ‘woocommerce_after_calculate_totals’, array( $this, ‘update_free_products_in_cart’ ), 8 );

//Set price to 0.00 for free products
add_filter( ‘woocommerce_add_cart_item’, array( $this, ‘filter_woocommerce_add_cart_item’ ), PHP_INT_MAX, 6 ); // mark the free products as such
add_filter( ‘woocommerce_get_cart_item_from_session’, array( $this, ‘filter_woocommerce_get_cart_item_from_session’ ), PHP_INT_MAX, 3 ); // mark the free products as such

// overwrite values (price 0.00) if it’s a free product
add_filter( ‘woocommerce_product_get_price’, array( $this, ‘filter_woocommerce_product_get_price’ ), PHP_INT_MAX, 2 );
add_filter( ‘woocommerce_product_variation_get_price’, array( $this, ‘filter_woocommerce_product_get_price’ ), PHP_INT_MAX, 2 );

// overwrite subtotal of 0.00
add_filter( ‘woocommerce_coupon_discount_amount_html’, array( $this, ‘filter_woocommerce_coupon_discount_amount_html’ ), 8, 2 );

//A free product coupon always has a value (for Auto coupon)
add_filter( ‘wjecf_coupon_has_a_value’, array( $this, ‘filter_wjecf_coupon_has_a_value’ ), 10, 2 ); // if coupon grants free products, it has a value! Required for Auto Coupons
add_filter( ‘woocommerce_coupon_is_valid_for_product’, array( $this, ‘filter_woocommerce_coupon_is_valid_for_product’ ), 10, 4 ); //don’t count the free items for coupon restrictions

add_action( ‘woocommerce_cart_emptied’, array( $this, ‘woocommerce_cart_emptied’ ) );