Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('woocommerce_cart_calculate_fees', 'add_discount_for_shipping_method', 10, 1);
- function add_discount_for_shipping_method($cart) {
- // Below check required ONLY if you can't control the deployment of this snippet.
- // It **must** execute on FRONT END ONLY.
- if (is_admin() && !defined('DOING_AJAX')) {
- return;
- }
- $targeted_shipping_method = 'flat_rate:3'; // Change this depending on your shipping method (slug:id)
- $discount = -5; // Applied discount in currency units
- $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
- $chosen_shipping_method = reset($chosen_shipping_methods);
- if($chosen_shipping_method == $targeted_shipping_method) {
- $cart->add_fee(__('Shipping Discount', 'woocommerce'), $discount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement