[英]Redirect to Checkout scrolling to billing details on add to cart in WooCommerce
I am trying to achieve a new button on the archive which will add the product to the cart, redirect to the checkout page and scroll down to the billing details. 我正在尝试在归档文件上实现一个新按钮,该按钮会将产品添加到购物车,重定向到结帐页面并向下滚动到帐单明细。
Nothing happens when using this code: 使用此代码没有任何反应:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url()#billing_details;
return $checkout_url;
}
It gives on error for this line: 它给出了这一行的错误:
$checkout_url = $woocommerce->cart->get_checkout_url()#billing_details;
Since WooCommerce 3, your code is outdated and you need to append #billing_details
as a string like: 从WooCommerce 3开始,您的代码已过时,您需要将#billing_details
作为字符串追加:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
return wc_get_checkout_url() . '#billing_details';
}
Now by default
#billing_details
doesn't exist, so you could use instead#customer_details
现在默认情况下#billing_details
不存在,因此您可以改用#customer_details
Code goes in functions.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的functions.php文件中。 Tested and work. 经过测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.