custom discount with php
-
Hello,
I’m using a custom php function to add a 10% discount on cart when people select the local pickup shipping method.
Any help on how to display it on the invoice ?
Thanks !
Alexis
here is the function :
add_action( 'woocommerce_cart_calculate_fees', 'custom_discount_for_pickup_shipping_method', 10, 1 ); function custom_discount_for_pickup_shipping_method( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $percentage = 10; // <=== 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( __('Réduction Clique & Collecte') . ' (' . $percentage . '%)', -$discount ); } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘custom discount with php’ is closed to new replies.