【问题标题】:Order items in a JS tracking code on Order received page in Woocommerce在 Woocommerce 中收到的订单页面上的 JS 跟踪代码中订购商品
【发布时间】:2019-03-17 22:24:57
【问题描述】:

我正在尝试在 Woocommerce 感谢页面中集成跟踪代码。我只找到了要填写的订单 ID。但我不知道如何为订单商品数据完成此操作。

这是我的实际代码:

<script type="text/javascript">
ADMITAD = window.ADMITAD || {};

ADMITAD.Invoice = ADMITAD.Invoice || {};

ADMITAD.Invoice.broker = "adm";     // deduplication parameter (for Admitad by default)

ADMITAD.Invoice.category = "1";     // action code (defined during integration)


var orderedItem = [];               // temporary array for product items


// repeat for every product item in the cart

orderedItem.push({

  Product: {

  productID: 'product_id', // internal product ID (not more than 100 characters, the same as in your product feed)

  category: '1',               // tariff code (defined during integration)

  price: 'price',          // product price

  priceCurrency: "RON",        // currency code in the ISO-4217 alfa-3 format

 },

 orderQuantity: '{{quantity}}',   // product quantity

 additionalType: "sale"           // always sale

 });


ADMITAD.Invoice.referencesOrder = ADMITAD.Invoice.referencesOrder || [];
// adding items to the order

ADMITAD.Invoice.referencesOrder.push({

  orderNumber: "<?php echo $order->get_id(); ?>;", // internal order ID (not more than 100 characters)

  orderedItem: orderedItem

});

// Important! If order data is loaded via AJAX, uncomment this string. 

// ADMITAD.Tracking.processPositions();

</script>

感谢任何帮助。

【问题讨论】:

    标签: javascript php wordpress woocommerce tracking


    【解决方案1】:

    以下重新访问的代码添加了正确的订单项目循环并使用“收到订单”页面(谢谢)专用动作挂钩:

    add_action( 'woocommerce_thankyou', 'js_tracking_thank_you_page', 90, 1 );
    function js_tracking_thank_you_page( $order_id ) {
        // Get the WC_Order instance Object
        $order = wc_get_order( $order_id );
    
        // Output
        ?>
        <script type="text/javascript">
        ADMITAD = window.ADMITAD || {};
    
        ADMITAD.Invoice = ADMITAD.Invoice || {};
    
        // deduplication parameter (for Admitad by default)
        ADMITAD.Invoice.broker = "adm";
    
        // action code (defined during integration)
        ADMITAD.Invoice.category = "1";
    
        // temporary array for product items
        var orderedItem = [];
    
        <?php
        // Loop through Order items
        foreach( $order->get_items() as $item ) :
            $product = $item->get_product();
        ?>
        orderedItem.push({
    
          Product: {
            // internal product ID (not more than 100 characters, the same as in your product feed)
            productID: '<?php echo $item->get_product_id(); ?>',
    
            // tariff code (defined during integration)
            category: '1',
    
            // product price
            price: '<?php echo $product->get_price(); ?>',
    
            // currency code in the ISO-4217 alfa-3 format
            priceCurrency: '<?php echo $order->get_currency(); ?>',
          },
          // product quantity
          orderQuantity: '<?php echo $item->get_quantity(); ?>',
    
          additionalType: "sale" // always sale
    
        });
        <?php endforeach; // End of Loop ?>
    
        // adding items to the order
        ADMITAD.Invoice.referencesOrder = ADMITAD.Invoice.referencesOrder || [];
    
        ADMITAD.Invoice.referencesOrder.push({
          // internal order ID (not more than 100 characters)
          orderNumber: "<?php echo $order->get_id(); ?>;",
    
          orderedItem: orderedItem
    
        });
    
        // Important! If order data is loaded via AJAX, uncomment this string.
        // ADMITAD.Tracking.processPositions();
        </script>
        <?php
    }
    

    它应该可以工作(已测试)

    相关:


    加法 - 实时货币转换

    1) 安装并激活这个免费插件:Euro FxRef Currency Converter

    2) 启用从“RON”到“EUR”的自动货币转换(产品价格示例)。

    替换:

    // product price
    price: '<?php echo $product->get_price(); ?>',
    

    通过以下方式:

    // Converted product price (rounded with 2 decimals)
    <?php $price = EuroFxRef::convert( $product->get_price(), 'RON', 'EUR' ); ?>
    price: '<?php echo round( $price, 2 );  ?>',
    

    经过测试并且有效……这应该可以解决问题。

    【讨论】:

    • 非常感谢,伙计。非常感谢。上帝祝福你 !你是大师。谢谢。干杯
    • 再次感谢。顺便说一句,是否有机会自动从我们的货币 RON 转换为 EUR,因为 admissionad 平台只能使用 EUR?
    • 我刚刚接受了你的回答。你让我今天一整天都感觉很好。谢谢
    • @DanielFlorea 在我的回答末尾添加了一个相关的补充,应该可以解决您的货币兑换问题……试试看。
    猜你喜欢
    • 1970-01-01
    • 2019-04-10
    • 2016-08-19
    • 2019-03-14
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 2021-04-02
    相关资源
    最近更新 更多