66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Nosara Tracks for WooCommerce
|
||
|
*
|
||
|
* @package WooCommerce\Tracks
|
||
|
*/
|
||
|
|
||
|
defined( 'ABSPATH' ) || exit;
|
||
|
|
||
|
/**
|
||
|
* This class adds actions to track usage of WooCommerce.
|
||
|
*/
|
||
|
class WC_Site_Tracking {
|
||
|
|
||
|
/**
|
||
|
* Send a Tracks event when a product is updated.
|
||
|
*
|
||
|
* @param int $product_id Product id.
|
||
|
* @param array $post WordPress post.
|
||
|
*/
|
||
|
public static function tracks_product_updated( $product_id, $post ) {
|
||
|
if ( 'product' !== $post->post_type ) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$properties = array(
|
||
|
'product_id' => $product_id,
|
||
|
);
|
||
|
|
||
|
WC_Tracks::record_event( 'update_product', $properties );
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if tracking is enabled.
|
||
|
*
|
||
|
* @return bool
|
||
|
*/
|
||
|
public static function is_tracking_enabled() {
|
||
|
/**
|
||
|
* Don't track users who haven't opted-in to tracking or if a filter
|
||
|
* has been applied to turn it off.
|
||
|
*/
|
||
|
if ( 'yes' !== get_option( 'woocommerce_allow_tracking' ) ||
|
||
|
! apply_filters( 'woocommerce_apply_user_tracking', true ) ) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if ( ! class_exists( 'WC_Tracks' ) ) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Init tracking.
|
||
|
*/
|
||
|
public static function init() {
|
||
|
if ( ! self::is_tracking_enabled() ) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
add_action( 'edit_post', array( 'WC_Site_Tracking', 'tracks_product_updated' ), 10, 2 );
|
||
|
}
|
||
|
}
|