Beacon.php
1 week ago
BeaconClickedAjax.php
1 week ago
BeaconDeactivationTracker.php
1 week ago
BeaconDisplayStrategy.php
1 week ago
BeaconDisplayStrategy.php
62 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class BeaconDisplayStrategy |
| 4 | * |
| 5 | * @package WPDesk\FS\TableRate |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\TableRate\Beacon; |
| 9 | |
| 10 | use Exception; |
| 11 | use FSVendor\WPDesk\Beacon\BeaconGetShouldShowStrategy; |
| 12 | use WC_Shipping_Zones; |
| 13 | use WPDesk\FS\TableRate\ShippingMethodSingle; |
| 14 | use WPDesk_Flexible_Shipping; |
| 15 | |
| 16 | /** |
| 17 | * Beacon display strategy. |
| 18 | */ |
| 19 | class BeaconDisplayStrategy extends BeaconGetShouldShowStrategy { |
| 20 | |
| 21 | /** |
| 22 | * BeaconDisplayStrategy constructor. |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | $conditions = [ |
| 26 | [ |
| 27 | 'page' => 'wc-settings', |
| 28 | 'tab' => 'shipping', |
| 29 | ], |
| 30 | ]; |
| 31 | parent::__construct( $conditions ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Should Beacon be visible? |
| 36 | * |
| 37 | * @return bool |
| 38 | */ |
| 39 | public function shouldDisplay() { |
| 40 | if ( parent::shouldDisplay() && ! wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) ) { |
| 41 | if ( isset( $_GET['instance_id'] ) ) { // phpcs:ignore |
| 42 | $instance_id = sanitize_text_field( $_GET['instance_id'] ); // phpcs:ignore |
| 43 | try { |
| 44 | $shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id ); |
| 45 | if ( $shipping_method && ( ( $shipping_method instanceof WPDesk_Flexible_Shipping ) || ( $shipping_method instanceof ShippingMethodSingle ) ) ) { |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | } catch ( Exception $e ) { |
| 50 | |
| 51 | return false; |
| 52 | } |
| 53 | } |
| 54 | if ( isset( $_GET['section'] ) && sanitize_key( $_GET['section'] ) === 'flexible_shipping_info' ) { // phpcs:ignore |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 |