Tracker
2 weeks ago
Assets.php
2 weeks ago
FreeShippingNotice.php
2 weeks ago
FreeShippingNoticeData.php
2 weeks ago
FreeShippingNoticeGenerator.php
2 weeks ago
FreeShippingNoticeRenderer.php
2 weeks ago
LffsNoticeTextFormatValidator.php
2 weeks ago
NoticeTextSettings.php
2 weeks ago
ProgressBarSettings.php
2 weeks ago
Tracker.php
2 weeks ago
Tracker.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FS\TableRate\FreeShipping; |
| 4 | |
| 5 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 6 | |
| 7 | /** |
| 8 | * Can append free shipping data to tracker. |
| 9 | */ |
| 10 | class Tracker implements Hookable { |
| 11 | |
| 12 | const PROGRESS_BAR_COUNT = 'method_free_shipping_progress_bar_count'; |
| 13 | const NOTICE_TEXT_COUNT = 'method_free_shipping_notice_text_count'; |
| 14 | |
| 15 | public function hooks() { |
| 16 | add_filter( 'flexible-shipping/tracker/method-settings', [ $this, 'append_free_shipping_data_to_tracker_data' ], 10, 2 ); |
| 17 | } |
| 18 | |
| 19 | public function append_free_shipping_data_to_tracker_data( $data, $shipping_method_settings ) { |
| 20 | if ( ! is_array( $data ) || ! is_array( $shipping_method_settings ) ) { |
| 21 | return $data; |
| 22 | } |
| 23 | |
| 24 | if ( ! isset( $data[ self::PROGRESS_BAR_COUNT ] ) ) { |
| 25 | $data[ self::PROGRESS_BAR_COUNT ] = 0; |
| 26 | } |
| 27 | if ( isset( $shipping_method_settings[ ProgressBarSettings::FIELD_NAME ] ) && $shipping_method_settings[ ProgressBarSettings::FIELD_NAME ] === 'yes' ) { |
| 28 | $data[ self::PROGRESS_BAR_COUNT ]++; |
| 29 | } |
| 30 | |
| 31 | if ( ! isset( $data[ self::NOTICE_TEXT_COUNT ] ) ) { |
| 32 | $data[ self::NOTICE_TEXT_COUNT ] = 0; |
| 33 | } |
| 34 | if ( isset( $shipping_method_settings[ NoticeTextSettings::FIELD_NAME ] ) && $shipping_method_settings[ NoticeTextSettings::FIELD_NAME ] !== '' ) { |
| 35 | $data[ self::NOTICE_TEXT_COUNT ]++; |
| 36 | } |
| 37 | |
| 38 | return $data; |
| 39 | } |
| 40 | |
| 41 | } |
| 42 |