每次客户点击"下订单"我需要添加Facebook Pixel代码来跟踪事件。在WooCommerce结帐页面上。
我试图在Checkout模板上找到按钮行,然后按照以下方式进行编辑:
<button onClick="fbq('track', 'AddPaymentInfo');">Place Order</button>
但是我无法找到该按钮的代码。
我该如何添加代码?
或者我在哪里可以找到要编辑的行?它是哪个模板?
由于
答案 0 :(得分:3)
如果您想对结帐提交按钮进行一些更改,您将有两种方式:
1)使用隐藏在 woocommerce_order_button_html
过滤器挂钩中的自定义函数,这样:
add_filter( 'woocommerce_order_button_html', 'custom_order_button_html');
function custom_order_button_html( $button ) {
// The text of the button
$order_button_text = __('Place order', 'woocommerce');
// HERE your Javascript Event
$js_event = "fbq('track', 'AddPaymentInfo');";
// HERE you make changes (Replacing the code of the button):
$button = '<input type="submit" onClick="'.$js_event.'" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '" />';
return $button;
}
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。
2)覆盖模板checkout / payment.php,您将定位此代码(第50行):
<?php echo apply_filters( 'woocommerce_order_button_html', '<input type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '" />' ); ?>
改为:
<?php
// Set HERE your javascript event
$js_event = $js_event = "fbq('track', 'AddPaymentInfo');";
echo apply_filters( 'woocommerce_order_button_html', '<input type="submit" onClick="'.$js_event.'" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '" />' ); ?>
相关文档: