gpt4 book ai didi

php - 在 Woocommerce 中的购物车和结帐之间添加新步骤

转载 作者:行者123 更新时间:2023-12-02 20:27:18 29 4
gpt4 key购买 nike

有什么方法可以在 WooCommerce 中的购物车和结帐之间添加新步骤吗?

我想在 woocommerce 上的购物车和结账之间添加一个名为(模式)的新步骤


编辑:

我有 4 个步骤,当我单击按钮进入第 2 个步骤时,它不会,它只是将我重定向到一个新页面(自定义页面)

enter image description here

最佳答案

您首先需要在 WordPress 中为您的自定义步骤添加一个新页面。然后下面的代码将替换购物车页面中的按钮名称和链接。您必须在此代码中设置所需的按钮名称,并链接到两个按钮上的自定义页面(购物车页面和 Minicart 小部件)

// 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
}

代码位于事件子主题(或事件主题)的 function.php 文件中。已测试且有效。

enter image description here

enter image description here

关于php - 在 Woocommerce 中的购物车和结帐之间添加新步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49589905/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com