简体   繁体   English

重定向到Checkout滚动到WooCommerce中添加到购物车的账单详细信息

[英]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.

相关问题 Woocommerce添加到购物车按钮重定向到结帐 - Woocommerce add to cart button redirect to checkout 添加到购物车并重定向到 WooCommerce 中可变产品的结帐 - Add to cart and redirect to checkout for variable products in WooCommerce WooCommerce 添加到购物车后重定向到结帐 - WooCommerce after add to cart redirect to checkout WooCommerce Checkout:隐藏帐单详细信息 - WooCommerce Checkout: hide Billing details 在Woocommerce的结算明细之前添加新的自定义结帐字段? - Add a new custom checkout field before billing details in Woocommerce? 在结帐时添加一个按钮以清空购物车并重定向到Woocommerce中的商店页面 - Add a button in checkout to empty cart and redirect to shop page in Woocommerce 添加到购物车并重定向到 WooCommerce 中默认可变产品的结帐 - Add to cart and redirect to checkout for default variable products in WooCommerce 其他Woocommerce产品“添加到购物车”按钮,可重定向到结帐 - Additional Woocommerce product Add To Cart button that redirect to checkout Woocommerce添加到购物车重定向到Checkout不适用于具有变体的产品 - Woocommerce Add To Cart redirect to Checkout not working for product with variants 将添加到购物车按钮重定向到 WooCommerce 中 1 个特定登录页面的结帐页面 - Redirect add to cart button to checkout page for 1 specific landing page in WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM