Product add-ons plugin – Exclude add-on price from local pickup discount
-
Hello everyone,
Here is the plugin I’m using : https://docs.woocommerce.com/document/product-add-ons/
With this plugin I added a custom select box if user wants to add a wrap to the product. If the select box is checked, then the price of the wrap is added to the total cart.
But I also need to apply a custom discount only for “local pickup” shipping method. Here is how I implemented it :
// Add discount for local pickup Hook add_action( 'woocommerce_cart_calculate_fees', 'custom_discount_for_pickup_shipping_method', 10, 1 ); // Add discount for local pickup Function function custom_discount_for_pickup_shipping_method( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $percentage = 7; // <=== Discount percentage $chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0]; $chosen_shipping_method = explode(':', $chosen_shipping_method_id)[0]; // Only for Local pickup chosen shipping method if ( strpos( $chosen_shipping_method_id, 'local_pickup' ) !== false ) { // Calculate the discount $discount = $cart->get_subtotal() * $percentage / 100; // Add the discount $cart->add_fee( __('Offre Drive') . ' (-' . $percentage . '%)', -$discount ); } }
I’d like to get the select box addon price value and, if selected, exclude it from the local pickup discount.
I know the plugin uses the class “WC_Product_Addons” and maybe generate an array but what I’ve tried never worked.
Does anyone have an idea how to achieve this ?
- The topic ‘Product add-ons plugin – Exclude add-on price from local pickup discount’ is closed to new replies.