feat: Implement upsell functionality with repository and service layers
This commit is contained in:
53
public/hooks/analytics-hooks.php
Normal file
53
public/hooks/analytics-hooks.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use Sodino\Repositories\EventRepository;
|
||||
use Sodino\Services\TrackingService;
|
||||
|
||||
function sodino_get_tracking_service() {
|
||||
static $service = null;
|
||||
|
||||
if ($service === null) {
|
||||
$eventRepository = new EventRepository();
|
||||
$service = new TrackingService($eventRepository);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
add_action('template_redirect', 'sodino_track_product_view');
|
||||
add_action('woocommerce_add_to_cart', 'sodino_track_add_to_cart', 10, 6);
|
||||
add_action('woocommerce_before_checkout_form', 'sodino_track_checkout_start');
|
||||
add_action('woocommerce_thankyou', 'sodino_track_purchase', 10, 1);
|
||||
|
||||
function sodino_track_product_view() {
|
||||
if (is_admin() || !is_singular('product')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$product_id = get_the_ID();
|
||||
if (!$product_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
sodino_get_tracking_service()->trackProductView($product_id);
|
||||
}
|
||||
|
||||
function sodino_track_add_to_cart($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
|
||||
sodino_get_tracking_service()->trackAddToCart($product_id, $variation_id, $quantity);
|
||||
}
|
||||
|
||||
function sodino_track_checkout_start() {
|
||||
if (is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sodino_get_tracking_service()->trackCheckoutStart();
|
||||
}
|
||||
|
||||
function sodino_track_purchase($order_id) {
|
||||
sodino_get_tracking_service()->trackPurchase($order_id);
|
||||
}
|
||||
Reference in New Issue
Block a user