| Server IP : 104.26.2.156 / Your IP : 216.73.216.185 Web Server : nginx/1.27.1 System : Linux us-1 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64 User : vinodai ( 3134) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /storage/v1396/woofsite3/public_html/wp-content/plugins/klaviyo/includes/ |
Upload File : |
<?php
/**
* WooCommerceKlaviyo Viewed Product Functions
*
* Functions for Viewed Product tracking.
*
* @package WooCommerceKlaviyo
* @version 2.0.0
*/
// Priority 12 to add after Identify Browser.
add_action( 'wp_enqueue_scripts', 'load_viewed_product', 12 );
/**
* If on product page, get properties for Viewed Product metric. Enqueue viewed product
* javascript and pass event data to script.
*/
function load_viewed_product() {
if ( is_product() ) {
$product = wc_get_product();
$parent_product_id = $product->get_parent_id();
if ( $product->get_parent_id() === 0 ) {
$parent_product_id = $product->get_id();
}
$categories_array = get_the_terms( $product->get_id(), 'product_cat' );
if ( false === $categories_array ) {
$categories_array = array();
}
$categories = (array) wp_list_pluck( $categories_array, 'name' );
$item = array(
'title' => (string) $product->get_name(),
'product_id' => (int) $parent_product_id,
'variant_id' => (int) $product->get_id(),
'url' => (string) get_permalink( $product->get_id() ),
'image_url' => (string) wp_get_attachment_url( get_post_thumbnail_id( $product->get_id() ) ),
'price' => (float) $product->get_price(),
'categories' => $categories,
);
wp_enqueue_script( 'wck_viewed_product', plugins_url( '/js/wck-viewed-product.js', __FILE__ ), null, WCK_API::VERSION, true );
wp_localize_script( 'wck_viewed_product', 'item', $item );
}
}