FlexibleShippingMethodsChecker.php
1 week ago
ShippingMethod.php
1 week ago
WooSettingsPageChecker.php
1 week ago
WooSettingsPageChecker.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WooSettingsPageChecker |
| 4 | * |
| 5 | * @package WPDesk\FS\Helpers |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\Helpers; |
| 9 | |
| 10 | use WC_Shipping_Method; |
| 11 | use WC_Shipping_Zones; |
| 12 | use WPDesk\FS\TableRate\ShippingMethodSingle; |
| 13 | use WPDesk_Flexible_Shipping; |
| 14 | |
| 15 | /** |
| 16 | * Helper for WooCommerce Settings Page. |
| 17 | */ |
| 18 | class WooSettingsPageChecker { |
| 19 | /** |
| 20 | * @return bool |
| 21 | */ |
| 22 | public function is_fs_instance_method_edit(): bool { |
| 23 | $tab = $this->filter_input( INPUT_GET, 'tab' ); |
| 24 | $page = $this->filter_input( INPUT_GET, 'page' ); |
| 25 | |
| 26 | if ( 'wc-settings' !== $page || 'shipping' !== $tab ) { |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | $instance_id = absint( wp_unslash( $this->filter_input( INPUT_GET, 'instance_id' ) ) ); |
| 31 | |
| 32 | if ( ! $instance_id ) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | $shipping_method = $this->get_shipping_method( $instance_id ); |
| 37 | |
| 38 | if ( ! $shipping_method ) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | return is_a( $shipping_method, WPDesk_Flexible_Shipping::class ) || is_a( $shipping_method, ShippingMethodSingle::class ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param int $instance_id . |
| 47 | * |
| 48 | * @return bool|WC_Shipping_Method |
| 49 | * @codeCoverageIgnore |
| 50 | */ |
| 51 | protected function get_shipping_method( int $instance_id ) { |
| 52 | return WC_Shipping_Zones::get_shipping_method( $instance_id ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param int $type . |
| 57 | * @param string $var_name . |
| 58 | * |
| 59 | * @return mixed |
| 60 | * @codeCoverageIgnore |
| 61 | */ |
| 62 | protected function filter_input( int $type, string $var_name ) { |
| 63 | return filter_input( $type, $var_name ); |
| 64 | } |
| 65 | } |
| 66 |