flexible-shipping
/
src
/
WPDesk
/
FS
/
TableRate
/
Debug
/
MultipleShippingZonesMatchedSameTerritoryTracker.php
DebugTracker.php
2 weeks ago
MultipleShippingZonesMatchedSameTerritoryNotice.php
2 weeks ago
MultipleShippingZonesMatchedSameTerritoryTracker.php
2 weeks ago
NoShippingMethodsNotice.php
2 weeks ago
MultipleShippingZonesMatchedSameTerritoryTracker.php
50 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class MultipleShippingZonesMatchedSameTerritoryTracker |
| 4 | * |
| 5 | * @package WPDesk\FS\TableRate\Debug |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\TableRate\Debug; |
| 9 | |
| 10 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 11 | |
| 12 | /** |
| 13 | * Can append multiple shipping zones matched data to tracker. |
| 14 | */ |
| 15 | class MultipleShippingZonesMatchedSameTerritoryTracker implements Hookable { |
| 16 | |
| 17 | const OPTION_NAME = 'fs-multiple-zones-matched-notice-count'; |
| 18 | const TRACKER_DATA_NAME = 'multiple_zones_matched_notice_count'; |
| 19 | const PRIORITY_AFTER_FLEXIBLE_SHIPPING_TRACKER = \WPDesk_Flexible_Shipping_Tracker::TRACKER_DATA_FILTER_PRIORITY + 1; |
| 20 | |
| 21 | /** |
| 22 | * Hooks. |
| 23 | */ |
| 24 | public function hooks() { |
| 25 | add_action( 'flexible-shipping/notice/multiple-zone-matches-same-territory', array( $this, 'update_counter_option' ) ); |
| 26 | add_filter( 'wpdesk_tracker_data', array( $this, 'append_tracker_data' ), self::PRIORITY_AFTER_FLEXIBLE_SHIPPING_TRACKER ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return bool |
| 31 | */ |
| 32 | public function update_counter_option() { |
| 33 | return update_option( self::OPTION_NAME, (int) get_option( self::OPTION_NAME, 0 ) + 1 ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param array $data . |
| 38 | * |
| 39 | * @return array |
| 40 | */ |
| 41 | public function append_tracker_data( $data ) { |
| 42 | if ( is_array( $data ) && isset( $data['flexible_shipping'] ) && is_array( $data['flexible_shipping'] ) ) { |
| 43 | $data['flexible_shipping'][ self::TRACKER_DATA_NAME ] = (int) get_option( self::OPTION_NAME, 0 ); |
| 44 | } |
| 45 | |
| 46 | return $data; |
| 47 | } |
| 48 | |
| 49 | } |
| 50 |