在特定时间段(例如7天)后,如何在woocommerce上单击“隐藏”(隐藏)我的帐户>我的订单?

时间:2019-05-23 02:15:28

标签: php wordpress function woocommerce

我添加了一个按钮,该按钮仅在处于特定订单状态时才会显示。 因为这不是在Commerce中设置的按钮,所以我必须在下订单后7天隐藏该按钮。你能帮我吗?

最好

// Add button when order status is 'completed'

add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
	if ( $order->has_status( 'completed' ) ) {
	    $action_slug = 'specific_name';
	
	    $actions[$action_slug] = array(
	        'url'  => 'https://www.cjlogistics.com/ko/tool/parcel/reservation-return',
	        'name' => 'Withdraw',
	    );
    }
    return $actions;
}

1 个答案:

答案 0 :(得分:0)

请在下面找到代码段,这些代码段将在订单完成后的7天内显示取款按钮。希望代码易于理解。需要找到当前日期和订单完成日期,并据此找到两个日期之间的差额(即天数)

add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
    if ( $order->has_status( 'completed' ) ) {
        $action_slug = 'specific_name';

        /*This is the logic to get difference between order completed date and the current date*/        
        $date1 = $order->get_date_completed(); // Order completed date
        $date2 = date('Y-m-d'); //current date
        $diff = abs(strtotime($date2) - strtotime($date1));
        $days = floor(($diff)/ (60*60*24));

        /*If order completed days is less then 7 then show the Withdra button */
        if($days < 7){
            $actions[$action_slug] = array(
                'url'  => 'https://www.cjlogistics.com/ko/tool/parcel/reservation-return',
                'name' => 'Withdraw',
            );    
        }
    }
    return $actions;
}