Javascript “定制结帐”;下单“;按钮输出html

Javascript “定制结帐”;下单“;按钮输出html,javascript,php,wordpress,woocommerce,checkout,Javascript,Php,Wordpress,Woocommerce,Checkout,每次客户点击WooCommerce结账页面上的“下订单”,我都需要添加Facebook像素代码来跟踪事件 我已尝试在签出模板中找到按钮行,并按以下方式进行编辑: <button onClick="fbq('track', 'AddPaymentInfo');">Place Order</button> 下订单 但是我找不到按钮的代码 如何添加代码 或者在哪里可以找到要编辑的行?它是哪个模板 谢谢 如果您想对“签出提交”按钮进行一些更改,您将有两种方法: 1) 使用wo

每次客户点击WooCommerce结账页面上的“下订单”,我都需要添加Facebook像素代码来跟踪事件

我已尝试在签出模板中找到按钮行,并按以下方式进行编辑:

<button onClick="fbq('track', 'AddPaymentInfo');">Place Order</button>
下订单
但是我找不到按钮的代码

如何添加代码
或者在哪里可以找到要编辑的行?它是哪个模板

谢谢

如果您想对“签出提交”按钮进行一些更改,您将有两种方法:

1) 使用
woocommerce\u order\u button\u 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;
}
add_filter('woocommerce_order_button_html','custom_order_button_html');
函数自定义命令按钮html($button){
//按钮的文本
$order_button_text=_uuu('下订单','woocommerce');
//这里是您的Javascript事件
$js_event=“fbq('track','AddPaymentInfo');”;
//在此进行更改(替换按钮的代码):
$button='';
返回$按钮;
}
代码位于活动子主题(或主题)的function.php文件或任何插件文件中


2) 覆盖模板checkout/payment.php,您将以该代码为目标(第50行):


相关文件:


所有代码都经过测试并正常工作。以下是两种解决方案的输出:

谢谢@LoicTheAztec,我已经用插件尝试过了,但是在结帐页面中,我只能为整个页面设置一个事件,在本例中为“InitiateCheckout”事件,我想在用户填写付款数据时为按钮添加第二个特定事件。通过这种方式,我可以检测用户何时尝试付款但无法付款。如果我使用插件,并且每页只能调整一个事件,那么系统将以相同的方式注册离开页面的客户机和试图付款但遇到一些麻烦的客户机。不过还是要谢谢你!!非常感谢@LoicTheAztec的帮助,它运行得非常好,现在我正在注册活动,并在FB reports上看到它们。非常感谢你!!祝你度过愉快的一天:)@Melania很高兴它成功了……这是我在你的问题上发现的一个好把戏……祝你度过愉快的一天:)
<?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 ) . '" />' ); ?>