Last active
August 10, 2020 06:41
-
-
Save claudiulodro/e9ee61c748283eb7f0abe917c633bd85 to your computer and use it in GitHub Desktop.
WooCommerce Setup Wizard - Adding/Removing Setup Wizard steps.
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
<?php | |
/** | |
* This is simple demo showing how to add and remove steps for the WooCommerce Setup Wizard | |
*/ | |
/** | |
* Add new steps to the setup wizard. | |
* To insert new steps in the middle use array_slice | |
* | |
* @param array $steps - wizard steps info | |
* 'step_slug' => array ( | |
* 'name' => 'The Step Title', | |
* 'view' => 'render_callback', | |
* 'handler' => 'save_callback' | |
* ) | |
* @return array - modified $steps | |
*/ | |
function add_new_step( $steps ) { | |
// Remove default intro and "Next Steps" screen. | |
unset( $steps['introduction'] ); | |
unset( $steps['next_steps'] ); | |
$new_intro_steps = array( | |
'new_intro' => array( | |
'name' => 'My New Intro', | |
'view' => 'render_new_intro', | |
'handler' => '' | |
), | |
'new_step' => array( | |
'name' => 'My New Step', | |
'view' => 'render_new_step', | |
'handler' => 'save_new_step', | |
), | |
); | |
$new_end_step = array( | |
'end_step' => array( | |
'name' => 'New Recap', | |
'view' => 'render_end_step', | |
'handler' => '' | |
) | |
); | |
return $new_intro_steps + $steps + $new_end_step; | |
} | |
add_filter( 'woocommerce_setup_wizard_steps', 'add_new_step' ); | |
/** | |
* Render a new intro screen. The first screen in the wizard is an intro screen that doesn't | |
* show up in the steps progress bar at the top. | |
* | |
* @param WC_Admin_Setup_Wizard $setup_wizard | |
*/ | |
function render_new_intro( $setup_wizard ) { | |
?> | |
<h1>Welcome to this new intro!</h1> | |
<p class="wc-setup-actions step"> | |
<a href="<?php echo esc_url( $setup_wizard->get_next_step_link() ) ?>" class="button-primary button button-large button-next">Get Started</a> | |
</p> | |
<?php | |
} | |
/** | |
* Render a generic form step. | |
* | |
* @param WC_Admin_Setup_Wizard $setup_wizard | |
*/ | |
function render_new_step( $setup_wizard ) { | |
?> | |
<h1>My New Step</h1> | |
<form method="post"> | |
<p>Fill out this form.</p> | |
<table class="form-table" cellspacing="0"> | |
<tbody> | |
<tr> | |
<td>Input</td> | |
<td><input type="text" name="new_step_input" value="" /></td> | |
</tr> | |
</tbody> | |
</table> | |
<p class="wc-setup-actions step"> | |
<input type="submit" class="button-primary button button-large button-next" value="Continue" name="save_step" /> | |
<a href="<?php echo esc_url( $setup_wizard->get_next_step_link() ); ?>" class="button button-large button-next">Skip</a> | |
<?php wp_nonce_field( 'wc-setup' ); ?> | |
</p> | |
</form> | |
<?php | |
} | |
/** | |
* Save the generic form step. | |
* | |
* @param WC_Admin_Setup_Wizard $setup_wizard | |
*/ | |
function save_new_step( $setup_wizard ) { | |
check_admin_referer( 'wc-setup' ); | |
$response = esc_attr( $_POST['new_step_input'] ); | |
update_option( 'new_step_response', $response ); | |
wp_redirect( esc_url_raw( $setup_wizard->get_next_step_link() ) ); | |
exit; | |
} | |
/** | |
* Render a new end step. | |
* | |
* @param WC_Admin_Setup_Wizard $setup_wizard | |
*/ | |
function render_end_step( $setup_wizard ) { | |
?> | |
<h1>All Done!</h1> | |
<p><a href="<?php echo esc_url( $setup_wizard->get_next_step_link( 'new_intro' ) ); ?>">Back to the first step.</a><p> | |
<p><a href="<?php echo esc_url( $setup_wizard->get_next_step_link() ); ?>">To Dashboard.</a></p> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment