PluginProbe
Sendy / 3.0.3
Sendy v3.0.3
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 / src / ShippingMethods / PickupPointDelivery.php

PickupPointDelivery.php in Sendy 3.0.3, at src/ShippingMethods/PickupPointDelivery.php

88 lines 2.8 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 class PickupPointDelivery extends \WC_Shipping_Flat_Rate
6 {
7 public const ID = 'sendy_pickup_point';
8
9 public function __construct($instance_id = 0)
10 {
11 $this->id = self::ID;
12 $this->instance_id = absint($instance_id);
13 $this->method_title = __('Pickup Point Delivery', 'sendy');
14 $this->method_description = __('Let your customers choose a pick-up point', 'sendy');
15
16 $this->supports = [
17 'shipping-zones',
18 'instance-settings',
19 'instance-settings-modal',
20 ];
21
22 $this->init();
23 $this->init_form_fields();
24 $this->init_settings();
25
26 add_filter('woocommerce_shipping_instance_form_fields_' . $this->id, [$this, 'instance_form_fields'], 10, 1);
27 add_action('woocommerce_update_options_shipping_' . $this->id, [$this, 'process_admin_options']);
28 }
29
30 public function init_form_fields()
31 {
32 $this->form_fields = [];
33 }
34
35
36 public function calculate_shipping($package = [])
37 {
38 // Set free shipping rate if cart subtotal exceed minimum_for_free_shipping
39 $minimum_for_free_shipping = $this->get_option('minimum_for_free_shipping');
40
41 if ('' !== $minimum_for_free_shipping && $package['cart_subtotal'] > $minimum_for_free_shipping) {
42 $rate = [
43 'id' => $this->get_rate_id(),
44 'label' => $this->title,
45 'cost' => 0,
46 'package' => $package,
47 ];
48
49 $this->add_rate($rate);
50 } else {
51 parent::calculate_shipping($package);
52 }
53 }
54
55 /**
56 * @param array<string,array<string,mixed>> $form_fields
57 * @return array<string,array<string,mixed>>
58 */
59 public function instance_form_fields(array $form_fields): array
60 {
61 $form_fields['title']['default'] = $this->method_title;
62
63 $form_fields['minimum_for_free_shipping'] = [
64 // translators: %s contains the currency symbol of the shop
65 'title' => sprintf(esc_html__('Free shipping from %s', 'sendy'), get_woocommerce_currency_symbol()),
66 'type' => 'number',
67 'desc_tip' => esc_html__('Keep empty if you don’t want to use Free shipping', 'sendy'),
68 'default' => 0,
69 ];
70
71 $form_fields['carrier'] = [
72 'title' => __('Carrier', 'sendy'),
73 'type' => 'select',
74 'options' => [
75 'DHL' => 'DHL eCommerce',
76 'PostNL' => 'PostNL',
77 'DPD' => 'DPD',
78 ],
79 'class' => 'wc-enhanced-select',
80 'default' => 'class',
81 'description' => __('Select which carrier to show the pickup points for', 'sendy')
82 ];
83
84 return $form_fields;
85 }
86
87 }
88