Hi, I had the same issue and I’ve kinda figured out a work-around..
Before you do any of this make sure to backup your files in case something goes wrong!
We have to edit a couple of files:
1st: wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple.php
Find the button with name=”add-to-cart”, we need to add the missing data attributes to this button.
Replace that button with:
<button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" data-product_id="<?php echo esc_attr( $product->get_id() ); ?>" data-product_name="<?php echo esc_attr( $product->get_title() ); ?>" data-price="<?php echo esc_attr( $product->get_price() ); ?>" class="single_add_to_cart_button button alt<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>"> <?php echo esc_html( $product->single_add_to_cart_text() ); ?> </button>
2nd: wp-content/plugins/tiktok-for-woocommerce/admin/js/ajaxSnippet.js
On lines 8, 9 and 10 we need to convert ‘thisbutton‘ to a jQuery element.
Simply replace those variables with:
var product_id = $(thisbutton).data('product_id');
var product_name = $(thisbutton).data('product_name');
var price = $(thisbutton).data('price');
Later I encountered another issue with TikTok not tracking the conversion values so I changed the price variable to:
var price = $(thisbutton).data('price') ? $(thisbutton).data('price') : $(".single_add_to_cart_button").data('price') || "0";
It seems to work fine for now but I haven’t fully tested it yet.
3rd: wp-content/plugins/tiktok-for-woocommerce/pixel/Tt4b_Pixel_Class.php
I had some caching issues, you might too so let’s change the ajaxSnippet.js version on line 675 from ‘v1’ to ‘v2’.
wp_register_script( 'tt4b_ajax_script', plugins_url( '/admin/js/ajaxSnippet.js', dirname( __DIR__ ) . '/tiktok-for-woocommerce.php' ), [ 'jquery' ], 'v2', false );
And that should be it, good luck!
P.S: TikTok devs hook me up with some ad credit bro, I’m working hard out here
-
This reply was modified 10 months, 3 weeks ago by masihwoo.