It seems that there is a problem somewhere with your theme (or in a plugin), as the minicart button links always point to the right cart and checkout pages.
minicart按钮挂在woocommerce_widget_shopping_cart_buttons动作钩子中(在cart / mini-cart.php WooCommerce模板中).你会发现细节HERE on includes/wc-template-hooks.php核心文件.它调用显示按钮的2 functions.
First you should try to refresh WordPress Permalinks, going on WP Settings > Permalinks:
Just at the end of the page click on “save”. Empty your cart, and try it again to see if it changes something.
在下面的代码中,我首先删除原始按钮,然后将其替换为自定义链接的相同按钮.对于每一个,您可以将链接更改为满足您的需求(我已添加链接?id = 1(最后)仅用于测试目的,以检查更改):
add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
// Removing Buttons
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
// Adding customized Buttons
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_button_view_cart', 10 );
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_proceed_to_checkout', 20 );
}, 1 );
// Custom cart button
function custom_widget_shopping_cart_button_view_cart() {
$original_link = wc_get_cart_url();
$custom_link = home_url( '/cart/?id=1' ); // HERE replacing cart link
echo '' . esc_html__( 'View cart', 'woocommerce' ) . '';
}
// Custom Checkout button
function custom_widget_shopping_cart_proceed_to_checkout() {
$original_link = wc_get_checkout_url();
$custom_link = home_url( '/checkout/?id=1' ); // HERE replacing checkout link
echo '' . esc_html__( 'Checkout', 'woocommerce' ) . '';
}
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中.
所有代码都在Woocommerce 3上进行测试并且有效.