flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-show-decision
/
src
/
WooCommerce
/
ShippingMethodInstanceStrategy.php
flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-show-decision
/
src
/
WooCommerce
Last commit date
ShippingMethodInstanceStrategy.php
2 weeks ago
ShippingMethodStrategy.php
2 weeks ago
ShippingMethodInstanceStrategy.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\ShowDecision\WooCommerce; |
| 4 | |
| 5 | use FSVendor\WPDesk\ShowDecision\ShouldShowStrategy; |
| 6 | class ShippingMethodInstanceStrategy implements ShouldShowStrategy |
| 7 | { |
| 8 | private \WC_Shipping_Zones $shipping_zones; |
| 9 | private string $method_id; |
| 10 | public function __construct(\WC_Shipping_Zones $shipping_zones, string $method_id) |
| 11 | { |
| 12 | $this->shipping_zones = $shipping_zones; |
| 13 | $this->method_id = $method_id; |
| 14 | } |
| 15 | public function shouldDisplay(): bool |
| 16 | { |
| 17 | if ($this->isInShippingSettings()) { |
| 18 | if (isset($_GET['instance_id'])) { |
| 19 | $shipping_method = $this->shipping_zones::get_shipping_method(sanitize_key($_GET['instance_id'])); |
| 20 | if ($shipping_method instanceof \WC_Shipping_Method) { |
| 21 | return $shipping_method->id === $this->method_id; |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | return \false; |
| 26 | } |
| 27 | private function isInShippingSettings(): bool |
| 28 | { |
| 29 | if ($this->isGetParameterWithValue('page', 'wc-settings') && $this->isGetParameterWithValue('tab', 'shipping')) { |
| 30 | return \true; |
| 31 | } |
| 32 | return \false; |
| 33 | } |
| 34 | private function isGetParameterWithValue(string $parameter, string $value): bool |
| 35 | { |
| 36 | return isset($_GET[$parameter]) && $_GET[$parameter] === $value; |
| 37 | } |
| 38 | } |
| 39 |