| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use Automattic\WooCommerce\Utilities\OrderUtil; |
| 6 | 6 | use FKWCS\Gateway\Stripe\P24; |
| 7 | 7 | use WPFunnels\Wpfnl_functions; |
| 8 | +use WPFunnels\Rest\Controllers\DashboardController; | |
| 8 | 9 | |
| 9 | 10 | class StatHookHandler |
| 10 | 11 | { |
| 11 | 12 | |
| @@ -12,10 +13,12 @@ | ||
| 12 | 13 | public function __construct() |
| 13 | 14 | { |
| 14 | 15 | add_action('wpfunnels/funnel_order_placed', array($this, 'update_stat_data_from_order'), 10, 3); |
| 15 | 16 | add_action('woocommerce_order_status_changed', array($this, 'change_order_status'), 10, 4); |
| 17 | + add_action('template_redirect', array($this, 'track_funnel_checkout_visit'), 1); | |
| 18 | + add_action('wp_footer', array($this, 'track_native_checkout_visit')); | |
| 16 | 19 | |
| 17 | - if (class_exists('\Automattic\WooCommerce\Utilities\OrderUtil') && OrderUtil::custom_orders_table_usage_is_enabled()) { | |
| 20 | + if (class_exists('\Automattic\WooCommerce\Utilities\OrderUtil') && function_exists('wc_get_container') && OrderUtil::custom_orders_table_usage_is_enabled()) { | |
| 18 | 21 | add_action('woocommerce_delete_order', array($this, 'delete_stat_data')); |
| 19 | 22 | } else { |
| 20 | 23 | add_action('delete_post', array($this, 'delete_stat_data')); |
| 21 | 24 | } |
| @@ -135,8 +138,9 @@ | ||
| 135 | 138 | array( |
| 136 | 139 | 'order_id' => $order_id |
| 137 | 140 | ) |
| 138 | 141 | ); |
| 142 | + DashboardController::delete_dashboard_cache(); | |
| 139 | 143 | } else { |
| 140 | 144 | $wpdb->update( |
| 141 | 145 | $table, |
| 142 | 146 | array( |
| @@ -270,8 +274,43 @@ | ||
| 270 | 274 | 'order_id' => $order_id |
| 271 | 275 | ) |
| 272 | 276 | ); |
| 273 | 277 | } |
| 278 | + } | |
| 279 | + } | |
| 280 | + | |
| 281 | + | |
| 282 | + /** | |
| 283 | + * Track funnel checkout page visits. | |
| 284 | + * Runs at template_redirect priority 1, before any WC redirect hooks. | |
| 285 | + */ | |
| 286 | + public function track_funnel_checkout_visit() | |
| 287 | + { | |
| 288 | + if ( is_admin() ) { | |
| 289 | + return; | |
| 290 | + } | |
| 291 | + | |
| 292 | + if ( Wpfnl_functions::check_if_this_is_step_type( 'checkout' ) ) { | |
| 293 | + global $post; | |
| 294 | + $funnel_id = Wpfnl_functions::get_funnel_id_from_step( $post->ID ); | |
| 295 | + CheckoutTracker::track_visit( 'funnel', $funnel_id ); | |
| 296 | + CheckoutTracker::track_visit( 'store', 0 ); | |
| 297 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * Track native WooCommerce checkout page visits. | |
| 302 | + * wp_footer fires only when a full page renders — WC's empty-cart redirect | |
| 303 | + * calls exit() before this point, so no cart check is needed here. | |
| 304 | + * Works for both classic shortcode and block-based checkout. | |
| 305 | + */ | |
| 306 | + public function track_native_checkout_visit() | |
| 307 | + { | |
| 308 | + if ( ! function_exists( 'is_checkout' ) ) { | |
| 309 | + return; | |
| 310 | + } | |
| 311 | + if ( is_checkout() && ! is_wc_endpoint_url( 'order-received' ) && ! is_wc_endpoint_url( 'order-pay' ) ) { | |
| 312 | + CheckoutTracker::track_visit( 'store', 0 ); | |
| 274 | 313 | } |
| 275 | 314 | } |
| 276 | 315 | |
| 277 | 316 | } |