Reputation: 71
Is there any way to add a new step between cart and checkout in WooCommerce?
I wanted to add a new step called (mode) between cart and checkout on woocommerce
Edit:
I have 4 steps, when I click on the button to pass into the 2 step then it doesn't, it just redirect me into a new page (custom page)
Upvotes: 2
Views: 3568
Reputation: 253949
You need first to add a new page in WordPress for your custom Step. Then the code below will replace the button name and link in cart page. You will have to set in this code the desired button name and link to your custom page on both buttons (cart page and Minicart widget too)
// For cart page: replacing proceed to checkout button
add_action( 'woocommerce_proceed_to_checkout', 'change_proceed_to_checkout', 1 );
function change_proceed_to_checkout() {
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
add_action( 'woocommerce_proceed_to_checkout', 'custom_button_proceed_to_custom_page', 20 );
}
// For mini Cart widget: Replace checkout button
add_action( 'woocommerce_widget_shopping_cart_buttons', 'change_widget_shopping_cart_button_view_cart', 1 );
function change_widget_shopping_cart_button_view_cart() {
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_button_to_custom_page', 20 );
}
// Cart page: Displays the replacement custom button linked to your custom page
function custom_button_proceed_to_custom_page() {
$button_name = esc_html__( 'Custom page step', 'woocommerce' ); // <== button Name
$button_link = get_permalink( 168 ); // <== Set here the page ID or use home_url() function
?>
<a href="<?php echo $button_link;?>" class="checkout-button button alt wc-forward">
<?php echo $button_name; ?>
</a>
<?php
}
// Mini cart: Displays the replacement custom button linked to your custom page
function custom_button_to_custom_page() {
$button_name = esc_html__( 'Custom page', 'woocommerce' ); // <== button Name
$button_link = get_permalink( 168 ); // <== Set here the page ID or use home_url() function
?>
<a href="<?php echo $button_link;?>" class="checkout button wc-forward">
<?php echo $button_name; ?>
</a>
<?php
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Upvotes: 5