简体   繁体   English

避免在Woocommerce谢谢页面中加载脚本

[英]Avoid loading a script in Woocommerce thank you page

IN Woocommerce, I use Header & Footer plugin to add on body tag a tracking affiliate code for the whole site. 在Woocommerce中,我使用Header&Footer插件在body标签上添加了整个网站的跟踪会员代码。

The code is: 代码是:

<script async src="//go.linkwi.se/delivery/js/tl.js"></script>
<script>
window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)};lw.l=+new Date;
lw("setProgram", "12838");
lw("setDecimal", ".");
</script>

My affiliate partner ask me the code be disabled from woocommerce thank you page (according the image - Line935 to 940). 我的会员合作伙伴问我禁用woocommerce谢谢页面的代码(根据图像-Line935至940)。

woocommerce thank you page source code: woocommerce谢谢页面源代码:

woocommerce谢谢页面源代码

I think I need to add_filter action or something to disable it. 我想我需要add_filter动作或禁用它的东西。

Any help will be useful for this. 任何帮助都将对此有用。

UPDATE: If I remove the code from Header & Footer plugin is disabled from the whole site. 更新:如果我从页眉和页脚插件中删除了代码,则整个站点都被禁用。

Instead of using a plugin, use the following to avoid your script to be loaded on thankyou page. 代替使用插件,使用以下命令避免将脚本加载到thankyou页面上。

You have 2 choices: 您有2个选择:

1) On Footer (the best choice, I think) : 1)在页脚上(我认为是最佳选择)

add_action( 'wp_footer' , 'linkwi_delivery_script' );
function linkwi_delivery_script(){
    // Not on thankyou page
    if( is_wc_endpoint_url('order-received') ) return;
    ?>
    <script async src="//go.linkwi.se/delivery/js/tl.js"></script>
    <script>
    window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)};lw.l=+new Date;
    lw("setProgram", "12838");
    lw("setDecimal", ".");
    </script>
    <?php
}

2) On Header: 2)在标题上:

add_action( 'wp_head' , 'linkwi_delivery_script' );
function linkwi_delivery_script(){
    // Not on thankyou page
    if( is_wc_endpoint_url('order-received') ) return;
    ?>
    <script async src="//go.linkwi.se/delivery/js/tl.js"></script>
    <script>
    window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)};lw.l=+new Date;
    lw("setProgram", "12838");
    lw("setDecimal", ".");
    </script>
    <?php
}

Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 It should works. 它应该工作。

So finaly my code in child function.php it look like this. 因此,最后我在子function.php中的代码看起来像这样。

 // Utility function that contain Linkwise Affiliate script function linkwise_affiliate_scripts( $order_id ){ ## --- YOUR SETTINGS START BELOW --- ## $program_id = '12838'; // <== Your program number $decimal_sep = '.'; // Decimal separator $currency = '978'; // For "EUR" => See: https://en.wikipedia.org/wiki/ISO_4217 ## --- END SETTINGS --- ## $order = wc_get_order( $order_id ); $order_status = $order->get_status(); $items_string = array(); $count = 0; ?> <script async src="//go.linkwi.se/delivery/js/tlwt.js"></script> <script> window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)}; lw .l=+new Date; lw("setProgram", "<?php echo $program_id; ?>"); lw("setDecimal", "<?php echo $decimal_sep; ?>"); </script> <script> lw("setCurrency", "<?php echo $currency; ?>"); // Set your currency <?php foreach( $order->get_items() as $item ): $count++; $item_id = $item->get_id(); // The item ID // Get an instance of the WC_Product object $product = $item->get_product(); $product_id = $item->get_product_id(); // Product ID $price_excl_vat = wc_get_price_excluding_tax( $product ); // Unit price excluding VAT $item_qty = $item->get_quantity(); // Item quantity $payout = '1'; // (???) // The string for the <noscript> at the bottom $items_string[] = "itemid[$count]=$item_id&amp;itemprice[$count]=$price_excl_vat&amp;itemquantity[$count]=$item_qty&a mp;itempayout[$count]=$payout"; ?> lw("addItem", { id: "<?php echo $item_id; // Or can be the product ID (may be) ?>" ,price: "<?php echo $price_excl_vat; ?>" ,quantity: "<?php echo $item_qty; ?>" ,payout: "<?php echo $payout; ?>" }); <?php endforeach; // Set the array of items strings in a unique string $items_string = implode( '&amp;', $items_string ); ?> // Other items types <?php $coupon_discounts = $coupon_discounts_tax = 0; foreach( $order->get_items('coupon') as $item_coupon ){ $coupon_discounts += $item_coupon->get_discount(); $coupon_discounts_tax += $item_coupon->get_discount_tax(); } ?> lw("setCoupon", "<?php echo $coupon_discounts; ?>"); lw("thankyou", { orderid: "<?php echo $order_id; ?>" ,status: "<?php echo $order_status; ?>" }); </script> <noscript> <img src="//go.linkwi.se/delivery/acl.php?program=<?php echo $program_id; ?>&amp;decimal=<?php echo $decimal_sep; ?>&amp;<?php echo $items_string; ?>&amp;coupon_price=<?php echo $coupon_discounts; ?>&amp;status=<?php echo $order_status; ?>&amp;orderid=<?php echo $order_id; ?>" style="width:0px;height:0px;"/> </noscript> <?php echo 'test'; } add_filter( 'wp_footer', 'wc_linkwise_affiliate_order_received_integration' ); function wc_linkwise_affiliate_order_received_integration() { if ( ! is_wc_endpoint_url( 'order-received' ) ) return; // Exit global $wp; $order_id = absint( $wp->query_vars['order-received'] ); if ( empty($order_id) || $order_id == 0 ) return; // Exit linkwise_affiliate_scripts( $order_id ); // Run the Linkwise Affiliate } add_action( 'wp_footer' , 'linkwi_delivery_script' ); function linkwi_delivery_script(){ // Not on thankyou page if( is_wc_endpoint_url('order-received') ) return; ?> <script async src="//go.linkwi.se/delivery/js/tl.js"></script> <script> window.lw=window.lw||function(){(lw.q=lw.q||[]).push(arguments)};lw.l=+new Date; lw("setProgram", "12838"); lw("setDecimal", "."); </script> <?php } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM