繁体   English   中英

如何在特定时间段(例如7天)my-account> my-orders on woocommerce后按钮隐藏(隐藏)?

[英]How to button Invisible (hide) after specific time period (e.g. 7days) my-account > my-orders on woocommerce?

我添加了一个按钮,只有在处于特定订单状态时才会出现。 因为它不是在Commerce中设置的按钮,所以我必须在下订单后七天隐藏该按钮。 你可以帮帮我吗?

最好,

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

请在下面的代码片段中找到订单完成后七天的退出按钮。 希望代码易于理解。 需要找到当前日期和订单完成日期,并在此基础上我们需要找到两个日期之间的差异(即天数)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM