中我的帐户订单列表上的条件取消按钮

中我的帐户订单列表上的条件取消按钮

本文介绍了Woocommerce 中我的帐户订单列表上的条件取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是参考

我做了 LoicTheAztec 提供的相同功能:

add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'custom_valid_order_statuses_for_cancel', 10, 2 );函数 custom_valid_order_statuses_for_cancel( $statuses, $order ){//在此处设置您希望取消按钮出现的订​​单状态$custom_statuses = array( 'pending', 'processing', 'on-hold', 'failed' );//在此处设置延迟(以天为单位)$duration = 3;//3天//更新:获取订单 ID 和 WC_Order 对象if( isset($_GET['order_id']))$order = wc_get_order( absint( $_GET['order_id'] ) );$delay = $duration*24*60*60;//(持续时间以秒为单位)$date_created_time = strtotime($order->get_date_created());//创建日期时间戳$date_modified_time = strtotime($order->get_date_modified());//修改日期时间戳$now = strtotime("现在");//现在时间戳//使用创建日期时间戳if ( ( $date_created_time + $delay ) >= $now ) return $custom_statuses;否则返回 $status;}
解决方案

I have found the following turn around (a very light update) that should solve the issue:

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;
}

Code goes in function.php file of your active child theme (or active theme). It should work now.

这篇关于Woocommerce 中我的帐户订单列表上的条件取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 04:48