• Resolved shamratdewan

    (@shamratdewan)


    I trying to capture remove item from cart. The product ID is in a js variable but its not assigning it to datalayer. it shows the name of the variable rather then value.

    how i should pass the variable to datalayer or is it possible to change the js variable to a php variable. the code below is on wordpress function.php file

    sample code

    if (document.querySelectorAll('a.remove')) {
                document.querySelectorAll('a.remove').forEach((el) => {
                    el.addEventListener('click', (e) => {
    var Producid= el.getAttribute('data-product_id');
    //console.log(Producid);
    
    window.dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
    window.dataLayer.push({
      'event': 'removeFromCart',
      'ecommerce': {
        'remove': {                               
          'products': [{                         
              'name': 'Remove Triblend Android T-Shirt',
              'id': Producid, // this variable Producid not print value it just showing name of the variable
              'price': '15.25',
              'brand': 'Google',
              'category': 'Apparel',
              'variant': 'Gray',
              'quantity': 1
          }]
        }
      }
    });

    or how do i access product details that is removed from cart

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    Thanks for posting your question. Please note that our support for custom code is really limited in this forum.

    Since this is a development topic, I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack.

    Thank you.

    We haven’t heard back from you in a while, (I think that at this point you have been able to find a solution) so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘remove cart item datalayer’ is closed to new replies.