mediteranija
Forum Replies Created
-
I got an answer from the dev on the Facebook and it goes like this:
Currently, the constant define works only the first connection for each integration. But feel free to use the DB method as it’s safe to use. From the last version, all the keys are encrypted in the database so even your DB get compromised, hacker can’t decrypt the key.
So, this thread is successfully resolved. Just use the database for Mailgun or other connections for now. I hope they’ll introduce the possibility of setting up more than one connection in wp-config.php one day.
RESOLVED
First of all, it’s not a bug. BUT, it looks like something has changed during the last update – with GTM4WP or with WC.
The GTM4WP wasn’t pushing Add To Cart event because it wasn’t creating an <span> element with the product’s data inside my loop.
After I’ve added this line of code right before my Add To Cart button:
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
, everything got back to normal.It’s a hook which isn’t documented here, but it’s need for GTM4WP to work on archive pages or inside product lists.
Before the last updates, I didn’t have this hook inside my code and everything worked. I had only:
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
, so maybe that was a change.Hi Thomas,
thank you a lot for your tips. Those were very helpful and pushed me on the right track!
I have continued with “trial & error” and finally got the job done. It was a little bit more tricky with Add To Cart button on the Product Detail page. I wasn’t aware of the form element!
I’ll share my own experience here, maybe it will help someone else. Especially if they use Oxygen builder to build custom templates and repeaters (loops) for Woocommerce pages.
1) ADD TO CART IN PRODUCT LISTS (e.g. Shop page, Category page, product’s repeater module in Oxygen)
– add class “product” on repeater module (or any other list/loop wrapper) and don’t use this same class on Add to cart button (this was my mistake!)
– I think this is optional, but I have used this code<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
to begin with my product card/container. This code adds a lot of additional classes that are connected to the looped post/product
– right after the upper code, you need to add this simple code<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
. Without it, GTM4WP can’t add its own code that is necessary to push data in dataLayer
– on Add to cart button, I have the following classes: button product_type_simple add_to_cart_button ajax_add_to_cart. It works for me, maybe it will for you. If not, try to take away some of them, but add_to_cart_button is a must!2) ADD TO CART ON PRODUCT DETAILS PAGE (aka single product page)
– Thomas (the developer of this great plugin) has appointed me in the right direction -> I didn’t implement the Add to cart button 100% properly (even if it worked alright). I needed to add the additional code and it was all about adding the form element and the ATC button would go inside it. This is my code, please tweak it to your needs!
<?php global $product; $name = $product->get_name(); $price = ( $product->get_price() ) * 1.25; // tax addition $url = get_permalink( $product->get_id() ); $image = $product->get_image('large'); $category = $product->get_categories(' '); $id = $product->get_id(); $sku = $product->get_sku(); $category_terms = get_the_terms( $post->ID, 'product_cat' ); foreach ( $category_terms as $category_term ) { $product_cat_id = $category_term->term_id; $product_cat_name = $category_term->name; break; } ?> <form class="cart my-own-product-form-element" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data'> <?php woocommerce_quantity_input( array( 'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), ) ); ?> <a class="my-own-product-atc-button button single_add_to_cart_button product_type_simple add_to_cart_button ajax_add_to_cart" aria-label="Add “<?php echo $name; ?>” in cart." href="/?add-to-cart=<?php echo $id; ?>" value="<?php echo $id; ?>" rel="nofollow" data-quantity="1" data-product_id="<?php echo $id; ?>" data-product_sku="<?php echo $sku; ?>" item_id="<?php echo $sku; ?>" item_name="<?php echo $name; ?>" item_brand="" price="<?php echo $price; ?>" item_category="<?php echo $product_cat_name; ?>" quantity="1" google_business_vertical="retail" id="<?php echo $sku; ?>"> ?? ADD TO CART </a> <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?> </form>
Once again, thank you Thomas Geiger (@duracelltomi) for your help! ??