Woocommerce - 在用户注销时清除购物车 [英] Woocommerce - Clear cart on user logout
本文介绍了Woocommerce - 在用户注销时清除购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 wordpress 网站中使用 woocommerce.
I am using woocommerce in wordpress site.
当该用户退出时,我需要清除该用户的购物车内容.
I need to clear cart contents of a logged in user when that user logs out.
我在插件设置中找不到任何相同的选项.
I am unable to find any options for the same in plugin settings.
任何人都可以告诉我实现相同目标的方法.
Anyone let me know a way to achieve the same.
推荐答案
使用 wp_logout
钩子清空购物车.将以下代码放在您主题的 function.php
或您自己的插件中.
Use wp_logout
hook to empty the cart. Place the below code in your theme's function.php
or in your own plugin.
function your_function() {
if( function_exists('WC') ){
WC()->cart->empty_cart();
}
}
add_action('wp_logout', 'your_function');
根据@helgatheviking 的解决方案
Edited: According to @helgatheviking 's solution
这篇关于Woocommerce - 在用户注销时清除购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文