admin管理员组文章数量:1327102
A user clicks a link to select the type of product they want so I do some work to compute the products to add using code like this:
WC()->cart->add_to_cart( 6842,1 );
then i try to go directly to checkout:
wp_safe_redirect( wc_get_checkout_url() );
But it does not add the product to the cart. But if I skip the redirect it works, but doesn't go where I want.
What am I doing wrong?
A user clicks a link to select the type of product they want so I do some work to compute the products to add using code like this:
WC()->cart->add_to_cart( 6842,1 );
then i try to go directly to checkout:
wp_safe_redirect( wc_get_checkout_url() );
But it does not add the product to the cart. But if I skip the redirect it works, but doesn't go where I want.
What am I doing wrong?
Share Improve this question edited Aug 6, 2020 at 13:23 mozboz 2,6281 gold badge12 silver badges23 bronze badges asked Aug 6, 2020 at 2:43 Ryan ScottRyan Scott 11 Answer
Reset to default 0You need to save the cart contents before redirect
WC()->session->save_data();
本文标签: Woocommerce addtocart() then wpsaferedirect() fails
版权声明:本文标题:Woocommerce add_to_cart() then wp_safe_redirect() fails 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742206235a2432866.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论