修改php購物車,php – 更改WooCommerce迷你购物车小部件上的购物车和结帐按钮链接...

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上进行测试并且有效.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值