PluginProbe
Sendy / trunk
Sendy vtrunk
3.4.6 3.4.7 trunk 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 All 32 releases
sendy / lib / ShippingMethods / ShippingMethodTrait.php

ShippingMethodTrait.php in Sendy trunk, at lib/ShippingMethods/ShippingMethodTrait.php

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sendy\WooCommerce\ShippingMethods;
4
5 use WC_Shipping_Flat_Rate;
6
7 /**
8 * @mixin WC_Shipping_Flat_Rate
9 */
10 trait ShippingMethodTrait
11 {
12 public function init_form_fields()
13 {
14 $this->form_fields = [];
15 }
16
17 public function calculate_shipping($package = [])
18 {
19 // Set free shipping rate if cart subtotal exceeds minimum_for_free_shipping
20 $minimum_for_free_shipping = $this->get_option('minimum_for_free_shipping');
21
22 if ('' !== $minimum_for_free_shipping && $package['cart_subtotal'] > $minimum_for_free_shipping) {
23 $rate = [
24 'id' => $this->get_rate_id(),
25 'label' => $this->title,
26 'cost' => 0,
27 'package' => $package,
28 ];
29
30 $this->add_rate($rate);
31 } else {
32 parent::calculate_shipping($package);
33 }
34 }
35
36 /**
37 * @param array<string,array<string,mixed>> $form_fields
38 * @return array<string,array<string,mixed>>
39 */
40 public function instance_form_fields(array $form_fields): array
41 {
42 $form_fields['title']['default'] = $this->method_title;
43
44 $form_fields['minimum_for_free_shipping'] = [
45 // translators: %s contains the currency symbol of the shop
46 'title' => sprintf(esc_html__('Free shipping from %s', 'sendy'), get_woocommerce_currency_symbol()),
47 'type' => 'number',
48 'desc_tip' => esc_html__('Keep empty if you don’t want to use Free shipping', 'sendy'),
49 'default' => 0,
50 ];
51
52 return $form_fields;
53 }
54 }
55