簡體   English   中英

Woocommerce中我的帳戶訂單列表上的有條件取消按鈕

[英]Conditional Cancel Button on my account orders list in Woocommerce

這是參考“ 使用我的客戶插件的取消”插件在“我的帳戶訂單”列表上添加“取消”按鈕的答案:

我還嘗試將函數添加到functions.php中,並且也得到了過多的參數錯誤: 在此處輸入圖片說明

我執行了LoicTheAztec提供的相同功能:

add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'custom_valid_order_statuses_for_cancel', 10, 2 );
function custom_valid_order_statuses_for_cancel( $statuses, $order ){

// Set HERE the order statuses where you want the cancel button to appear
$custom_statuses    = array( 'pending', 'processing', 'on-hold', 'failed' );

// Set HERE the delay (in days)
$duration = 3; // 3 days

// UPDATE: Get the order ID and the WC_Order object
if( isset($_GET['order_id']))
    $order = wc_get_order( absint( $_GET['order_id'] ) );

$delay = $duration*24*60*60; // (duration in seconds)
$date_created_time  = strtotime($order->get_date_created()); // Creation date time stamp
$date_modified_time = strtotime($order->get_date_modified()); // Modified date time stamp
$now = strtotime("now"); // Now  time stamp

// Using Creation date time stamp
if ( ( $date_created_time + $delay ) >= $now ) return $custom_statuses;
else return $statuses;
}

由於此掛鈎在Woocommerce核心代碼中使用了2次,每個掛鈎使用不同數量的參數:

處理起來很復雜,沒有出現任何問題……

我發現以下應解決的問題(非常輕松的更新)可以解決此問題:

add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'filter_valid_order_statuses_for_cancel', 20, 2 );
function filter_valid_order_statuses_for_cancel( $statuses, $order = '' ){

    // Set HERE the order statuses where you want the cancel button to appear
    $custom_statuses    = array( 'pending', 'processing', 'on-hold', 'failed' );

    // Set HERE the delay (in days)
    $duration = 3; // 3 days

    // UPDATE: Get the order ID and the WC_Order object
    if( ! is_object( $order ) && isset($_GET['order_id']) )
        $order = wc_get_order( absint( $_GET['order_id'] ) );

    $delay = $duration*24*60*60; // (duration in seconds)
    $date_created_time  = strtotime($order->get_date_created()); // Creation date time stamp
    $date_modified_time = strtotime($order->get_date_modified()); // Modified date time stamp
    $now = strtotime("now"); // Now  time stamp

    // Using Creation date time stamp
    if ( ( $date_created_time + $delay ) >= $now ) return $custom_statuses;
    else return $statuses;
}

代碼進入您的活動子主題(或活動主題)的function.php文件中。 現在應該可以工作了。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM