日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

购物车清除的php,php-如何清除废弃的woocommerce购物车

發布時間:2025/3/21 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 购物车清除的php,php-如何清除废弃的woocommerce购物车 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我遇到了這段代碼,該代碼用于在某些頁面加載時清除Woocommerce購物車.

但是,我想知道有沒有辦法在購物車被拋棄后對其進行清理?

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.

我對代碼進行了一些調整,以切換到24小時課程.我不確定您是否希望每隔幾分鐘刪除一次,因為這可能會導致性能提高.

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

}

標簽:cart,php,wordpress,woocommerce

來源: https://codeday.me/bug/20191013/1906640.html

總結

以上是生活随笔為你收集整理的购物车清除的php,php-如何清除废弃的woocommerce购物车的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。