Customizing checkout “Place Order” button output html

前端 未结 1 1129
北海茫月
北海茫月 2020-12-17 07:23

I need to add the Facebook Pixel code to track an event, every time a client clicks the \"Place Order\" on the WooCommerce checkout page.

I\'ve tried to find the bu

1条回答
  •  不知归路
    2020-12-17 07:54

    If you want to make some changes on the checkout submit button, you will have 2 ways:

    1) Using a custom function hooked in woocommerce_order_button_html filter hook, this way:

    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 = '';
    
        return $button;
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.


    2) Overriding the template checkout/payment.php and you will target this code (on line 50):

    ' ); ?>
    

    Changed to this:

    ' ); ?>
    

    Related documentation:

    • Template Structure + Overriding Templates via a Theme
    • Woocommerce templates file checkout/payment.php

    All code is tested and works. here is the output for both solutions:

    0 讨论(0)
提交回复
热议问题