简体   繁体   中英

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

I added a button that only appears when it is in a specific order status. Because it is not a button to set up in Commerce, I have to hide that button seven days after I place an order. Could you help me?

Best,

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

Please find below code snippet that will show the withdraw button for seven days after the completion of order. Hope the code is easy to understand. Need to find the current date and the order completed date and based on this we need to find the difference between the two dates (ie Number of days)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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