Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created December 4, 2025 10:11
Show Gist options
  • Select an option

  • Save xlplugins/417b042f9c7a9be4211bb566aabc5220 to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/417b042f9c7a9be4211bb566aabc5220 to your computer and use it in GitHub Desktop.
Funnelkit Checkout: Auto-Advance Multi-Step Checkout After Smart Login
if (!class_exists('WFACP_Auto_Advance_After_Login')) {
/**
* Class WFACP_Auto_Advance_After_Login
*
* Auto-trigger the next page button after user logs in via smart login
* on specific multi-step checkout forms
*
* @since 1.0.0
*/
class WFACP_Auto_Advance_After_Login {
/**
* Array of checkout form IDs where auto-next should trigger
*
* @var array
*/
private $target_checkout_ids = array(5564, 5566);
/**
* Delay in milliseconds before triggering next button
*
* @var int
*/
private $trigger_delay = 800;
/**
* Constructor - Initialize hooks
*/
public function __construct() {
add_action('wp_footer', array($this, 'auto_trigger_next_button'), 999);
add_action('wp_login', array($this, 'set_login_flag'), 10, 2);
}
/**
* Set a flag when user logs in to detect fresh login
*
* @param string $user_login Username
* @param WP_User $user User object
* @return void
*/
public function set_login_flag($user_login, $user) {
// Set a transient that expires in 30 seconds
// This will help us detect if the user just logged in
set_transient('wfacp_just_logged_in_' . $user->ID, true, 30);
}
/**
* Check if auto-trigger should run
*
* @return bool
*/
private function should_trigger() {
// Check if WooFunnels Aero Checkout is active
if (!class_exists('WFACP_Common') || !function_exists('WC')) {
return false;
}
// Get current checkout page ID
$checkout_id = WFACP_Common::get_id();
// Only run on specific checkout forms
if (!in_array($checkout_id, $this->target_checkout_ids, true)) {
return false;
}
// Only run if user is logged in
if (!is_user_logged_in()) {
return false;
}
// Check if WooCommerce session is available
if (!WC()->session) {
return false;
}
return true;
}
/**
* Check if this is a fresh login from smart login
*
* @param int $checkout_id Current checkout page ID
* @return bool
*/
private function is_fresh_login($checkout_id) {
// Check if this is a fresh login using WooCommerce session
$session_key = 'wfacp_auto_next_triggered_' . $checkout_id;
$already_triggered = WC()->session->get($session_key, false);
// If already triggered in this session, don't trigger again
if ($already_triggered) {
return false;
}
// Check if user just logged in (using transient)
$user_id = get_current_user_id();
$just_logged_in = get_transient('wfacp_just_logged_in_' . $user_id);
if ($just_logged_in) {
// Delete the transient so we don't trigger again
delete_transient('wfacp_just_logged_in_' . $user_id);
return true;
}
return false;
}
/**
* Auto-trigger next page button after smart login
* Hooked to wp_footer
*
* @return void
*/
public function auto_trigger_next_button() {
// Check if we should run
if (!$this->should_trigger()) {
return;
}
$checkout_id = WFACP_Common::get_id();
// Check if this is a fresh login
if (!$this->is_fresh_login($checkout_id)) {
return;
}
// Mark as triggered in WooCommerce session
$session_key = 'wfacp_auto_next_triggered_' . $checkout_id;
WC()->session->set($session_key, true);
// Output JavaScript to trigger next button
$this->output_trigger_script($checkout_id);
}
/**
* Output JavaScript to trigger the next button
*
* @param int $checkout_id Current checkout page ID
* @return void
*/
private function output_trigger_script($checkout_id) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
setTimeout(function() {
var $emailField = $('#billing_email');
if ($emailField.length === 0 || !$emailField.is(':visible')) {
return;
}
var emailValue = $emailField.val();
if (!emailValue || emailValue.trim() === '') {
return;
}
var $paymentSection = $('.wfacp_payment');
var isPaymentVisible = $paymentSection.length > 0 && $paymentSection.is(':visible');
if (isPaymentVisible) {
return;
}
var $nextButton = $('.wfacp_next_page_button');
if ($nextButton.length === 0 || !$nextButton.is(':visible')) {
return;
}
if ($nextButton.hasClass('wfacp-checking-user') ||
$nextButton.hasClass('wfacp-login-blocked') ||
$nextButton.prop('disabled')) {
return;
}
$nextButton.trigger('click');
}, <?php echo esc_js($this->trigger_delay); ?>);
});
</script>
<?php
}
}
// Initialize the class
new WFACP_Auto_Advance_After_Login();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment