039 4321 444
039 4321 444
0335006543
0335006543
1 Donate cho em ly cafe được hông ^^

Add Cancellation Button For Customers After Payment

huy-don-hang-sau-khi-thanh-toan

Add Cancellation Button For Customers After Payment

Similar to today’s e-commerce platforms, allowing customers to cancel orders after payment can help improve the shopping experience. While this may in the short term reduce your revenue, it contributes to an increase in conversion rates because customers will then trust more.

Today, flatsomea-z will show you how to add a “Cancel Order” button in your customer’s account page with a very simple code.

You just need to copy and paste the following code into the functions.php file and save it!

//Allow customers to cancel orders after payment
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 the statuses that you allow customers to cancel
$custom_statuses = array( 'completed', 'pending', 'processing', 'on-hold', 'failed' );

// Set the number of days to be allowed to cancel since placing an order
$duration = 3; // 3 days

// Get Order ID and WC_Order
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;
}

Tested and code working perfectly

Trả lời

Email của bạn sẽ không được hiển thị công khai.