购物车清除的php,php-如何清除废弃的woocommerce购物车
我遇到了這段代碼,該代碼用于在某些頁(yè)面加載時(shí)清除Woocommerce購(gòu)物車.
但是,我想知道有沒(méi)有辦法在購(gòu)物車被拋棄后對(duì)其進(jìn)行清理?
For triggering only on front page your function needs to look like this:
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( is_front_page() && isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
function is_front_page() returns true only on front page of your wordpress site. Also, you might detect any other page with function is_page() where you can pass any page title, ID or slug
解決方法:
From what I can see, WooCommerce 2.0.20 has a scheduled maintenance job that runs twice/day that will remove any cart sessions from the WordPress options table. The default expiration time is set to 48 hours from the time the user first created the cart. I’m guessing your standard WordPress scheduling routines (and server cron/at jobs) will need to be running properly for this to execute.
AFAIK there is no way to adjust the 48 hour rule via settings. You could write a filter in your theme or in an “adjacent” plugin.
我對(duì)代碼進(jìn)行了一些調(diào)整,以切換到24小時(shí)課程.我不確定您是否希望每隔幾分鐘刪除一次,因?yàn)檫@可能會(huì)導(dǎo)致性能提高.
add_filter('wc_session_expiring', 'so_26545001_filter_session_expiring' );
function so_26545001_filter_session_expiring($seconds) {
return 60 * 60 * 23; // 23 hours
}
add_filter('wc_session_expiration', 'so_26545001_filter_session_expired' );
function so_26545001_filter_session_expired($seconds) {
return 60 * 60 * 24; // 24 hours
}
標(biāo)簽:cart,php,wordpress,woocommerce
來(lái)源: https://codeday.me/bug/20191013/1906640.html
總結(jié)
以上是生活随笔為你收集整理的购物车清除的php,php-如何清除废弃的woocommerce购物车的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java空值转datetime,关于ja
- 下一篇: php 后台配置系统,使用 larave