-
-
Save anunay/271f8fd96574937d96108a6eba357461 to your computer and use it in GitHub Desktop.
From this code snippet you can create custom order status delivered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this code to your theme functions.php file or a custom plugin | |
add_action('init', 'register_order_status'); | |
//add status after completed | |
add_filter('wc_order_statuses', 'add_delivered_to_order_statuses'); | |
//Custom Statuses in admin reports | |
add_filter('woocommerce_reports_order_statuses', 'include_custom_order_status_to_reports', 20, 1); | |
// for automate woo to check order is paid | |
add_filter('woocommerce_order_is_paid_statuses', 'delivered_woocommerce_order_is_paid_statuses'); | |
/*** Register new status : Delivered | |
* https://www.zorem.com/how-to-create-custom-order-status-in-woocommerce/ | |
**/ | |
function register_order_status() | |
{ | |
register_post_status('wc-delivered', array( | |
'label' => __('Delivered', 'text-domain'), | |
'public' => true, | |
'show_in_admin_status_list' => true, | |
'show_in_admin_all_list' => true, | |
'exclude_from_search' => false, | |
'label_count' => _n_noop('Delivered <span class="count">(%s)</span>', 'Delivered <span class="count">(%s)</span>', 'text-domain') | |
)); | |
} | |
/* | |
* add status after completed | |
*/ | |
function add_delivered_to_order_statuses($order_statuses) | |
{ | |
$new_order_statuses = array(); | |
foreach ($order_statuses as $key => $status) { | |
$new_order_statuses[$key] = $status; | |
if ('wc-completed' === $key) { | |
$new_order_statuses['wc-delivered'] = __('Delivered', 'text-domain'); | |
} | |
} | |
return $new_order_statuses; | |
} | |
/* | |
* Adding the custom order status to the default woocommerce order statuses | |
*/ | |
function include_custom_order_status_to_reports($statuses) | |
{ | |
if ($statuses) | |
$statuses[] = 'delivered'; | |
return $statuses; | |
} | |
/* | |
* mark status as a paid. | |
*/ | |
function delivered_woocommerce_order_is_paid_statuses($statuses) | |
{ | |
$statuses[] = 'delivered'; | |
return $statuses; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment