PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.3.47
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.3.47
1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 All 178 releases
disco / functions / shipping.php

shipping.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.3.47, at functions/shipping.php

41 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Ensure the file is not accessed directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use Disco\App\Disco;
9
10 if ( ! function_exists( 'disco_add_free_shipping_rate' ) ) {
11
12 /**
13 * Add free shipping rate to the package. If any campaign matches, then apply free shipping.
14 *
15 * @param array $rates Array of rates found for the package.
16 * @return array
17 */
18 function disco_add_free_shipping_rate( $rates ) {
19 $is_free_shipping = ( new Disco )->apply_free_shipping( WC()->cart );
20
21 if ( ! $is_free_shipping ) {
22 return $rates;
23 }
24
25 foreach ( $rates as $rate_id => $rate ) {
26 if ( 'free_shipping' === $rate->method_id ) {
27 return $rates;
28 }
29 }
30
31 // If free shipping is not available, override rates with free shipping
32 // TODO: Add Label from campaign
33 $free_shipping_rate = new WC_Shipping_Rate( 'disco_free_shipping', __( 'Free Shipping', 'disco' ), 0, array(), 'disco_free_shipping' );
34 $rates['disco_free_shipping'] = $free_shipping_rate;
35
36 return $rates;
37 }
38
39 add_filter( 'woocommerce_package_rates', 'disco_add_free_shipping_rate', 100, 1 );
40 }
41