Created
December 10, 2025 13:28
-
-
Save xlplugins/b12507742af229a22f32ebb142b223e4 to your computer and use it in GitHub Desktop.
Add Plausible analytics tracking class to FunnelKit Checkout place order button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'woocommerce_order_button_html', function( $button_html ) { | |
| // Check if we're on a FunnelKit checkout page | |
| if ( ! function_exists( 'wfacp_template' ) ) { | |
| return $button_html; | |
| } | |
| $instance = wfacp_template(); | |
| if ( ! $instance ) { | |
| return $button_html; | |
| } | |
| // Add Plausible event class to the button | |
| // Handle both <button> and <input> element types | |
| if ( strpos( $button_html, '<button' ) !== false ) { | |
| // For <button> elements, add class to existing class attribute | |
| $button_html = preg_replace( | |
| '/(<button[^>]*class=["\'])([^"\']*)(["\'])/i', | |
| '$1$2 plausible-event-name=Complete+purchase$3', | |
| $button_html | |
| ); | |
| } elseif ( strpos( $button_html, '<input' ) !== false ) { | |
| // For <input> elements, add class to existing class attribute | |
| $button_html = preg_replace( | |
| '/(<input[^>]*class=["\'])([^"\']*)(["\'])/i', | |
| '$1$2 plausible-event-name=Complete+purchase$3', | |
| $button_html | |
| ); | |
| } | |
| return $button_html; | |
| }, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment