Renaming WooCommerce Order Status
Just renaming order status "Completed" to "Order Received", it's easy and can be accomplished this way with wc_order_statuses
hook (you will paste this snippet in your active child theme function.php
file):
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
if ( 'wc-completed' === $key )
$order_statuses['wc-completed'] = _x( 'Order Received', 'Order status', 'woocommerce' );
}
return $order_statuses;
}
Code goes in function.php file of your active child theme (or active theme). Tested and Works.Other related reference: How to create a custom order status in woocommerceUpdate 2018 - To rename, in Order list page:
• the bulk actions dropdown
• the order status tabs (with the count)
See: Rename multiple order statuses in Woocommerce
Rename multiple order statuses in Woocommerce
As Pending order status exist, you need also to rename the existing "Pending" status. If not you will get 2 different statuses with the same "Pending" label.
First to rename those order statuses:
add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );
function rename_order_statuses( $order_statuses ) {
$order_statuses['wc-completed'] = _x( 'Order Received', 'Order status', 'woocommerce' );
$order_statuses['wc-processing'] = _x( 'Paid', 'Order status', 'woocommerce' );
$order_statuses['wc-on-hold'] = _x( 'Pending', 'Order status', 'woocommerce' );
$order_statuses['wc-pending'] = _x( 'Waiting', 'Order status', 'woocommerce' );
return $order_statuses;
}
And Also in the bulk edit order list dropdown:add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_processing'] = __( 'Mark paid', 'woocommerce' );
$actions['mark_on-hold'] = __( 'Mark pending', 'woocommerce' );
$actions['mark_completed'] = __( 'Mark order received', 'woocommerce' );
return $actions;
}
And also this is needed (for the top menu):
foreach( array( 'post', 'shop_order' ) as $hook )
add_filter( "views_edit-$hook", 'shop_order_modified_views' );
function shop_order_modified_views( $views ){
if( isset( $views['wc-completed'] ) )
$views['wc-completed'] = str_replace( 'Completed', __( 'Order Received', 'woocommerce'), $views['wc-completed'] );
if( isset( $views['wc-processing'] ) )
$views['wc-processing'] = str_replace( 'Processing', __( 'Paid', 'woocommerce'), $views['wc-processing'] );
if( isset( $views['wc-on-hold'] ) )
$views['wc-on-hold'] = str_replace( 'On hold', __( 'Pending', 'woocommerce'), $views['wc-on-hold'] );
if( isset( $views['wc-pending'] ) )
$views['wc-pending'] = str_replace( 'Pending', __( 'Stucked', 'woocommerce'), $views['wc-pending'] );
return $views;
}
(Thanks to brasofilo : Change WP admin post status filter for custom post type)Code goes in function.php file of your active child theme (or active theme). Tested and works.
Since Woocommerce 3.3 to handle the preview popup (eye symbol) in admin order list:Replace order status names everywhere incl. Woocommerce admin order preview
Replace order status names everywhere incl. Woocommerce admin order preview
Your code made from Rename multiple order statuses in Woocommerce answer code already cover everything (90%), including:
Front end > my-account/orders, the Status column.
Front end > my-account/view-order/x, the summary line
Otherwise, if it doesn't work, it could be caused by other customizations from you theme, a plugin or your own customizations.
Now to handle Admin > orders, the preview popup (eye symbol) use the following code:
add_filter( 'woocommerce_admin_order_preview_actions', 'filter_admin_order_preview_actions', 10, 2 );
function filter_admin_order_preview_actions( $actions, $order ) {
$actions = array();
$status_actions = array();
if ( $order->has_status( array( 'pending' ) ) ) {
$status_actions['on-hold'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=on-hold&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'On-hold', 'woocommerce' ),
'title' => __( 'Change order status to on-hold', 'woocommerce' ),
'action' => 'on-hold',
);
}
if ( $order->has_status( array( 'pending', 'on-hold' ) ) ) {
$status_actions['processing'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Approved', 'woocommerce' ),
'title' => __( 'Change order status to approved', 'woocommerce' ),
'action' => 'processing',
);
}
if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
$status_actions['complete'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Completed', 'woocommerce' ),
'title' => __( 'Change order status to completed', 'woocommerce' ),
'action' => 'complete',
);
}
if ( $status_actions ) {
$actions['status'] = array(
'group' => __( 'Change status: ', 'woocommerce' ),
'actions' => $status_actions,
);
}
return $actions;
}
And to rename the status on Admin order list button when hovered:add_filter( 'woocommerce_admin_order_actions', 'rename_admin_order_status_action_button', 10, 2 );
function rename_admin_order_status_action_button( $actions, $order ) {
// Display the button for all orders that have a 'processing', 'pending' or 'on-hold' status
if ( isset($actions['processing']) ) {
$actions['processing']['name'] = __( 'Approved', 'woocommerce');
}
return $actions;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works. Effect of renaming the WooCommerce Order Status
By using the below code you can change the order status and order status label.
add_filter('wc_order_statuses', 'wc_renaming_order_status');
function wc_renaming_order_status($order_statuses) {
$order_statuses['wc-on-hold'] = _x('Order Received', 'Order status', 'woocommerce');
return $order_statuses;
}
Here the label of the order status is getting changed. It will not affect in any case where the status code ( on-hold
, completed
,...) is used.See the attached screenshots of the applied and tested OK.
WooCommerce - Renaming and using renamed order status
This is normal and your this specific case you could use some additional code, creating a function to display your custom renamed status:
function custom_status($order){
if($order->status == 'completed')
return _x( 'Paid', 'woocommerce' );
else
return $order->status;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.In your template page you will use it this way:
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>
<tr>
<td style="text-align:left;"><?php echo $order->get_order_number(); ?></td>
<td style="text-align:left;"><?php echo $order->billing_first_name; ?>
<?php echo $order->billing_last_name; ?></td>
<td style="text-align:left;"><?php echo $order->billing_company; ?></td>
<td style="text-align:left;"><?php echo custom_status($order); ?></td>
</tr>
<?php endwhile; ?>
This code is tested and works.Reference: Renaming WooCommerce Order Status
Adding multiple custom order statuses in Woocommerce
The following code, will add "Awaiting shipment" and "Verification" custom order statuses and it will replace the code from your question:
add_action( 'init', 'register_custom_statuses_as_order_status' );
function register_custom_statuses_as_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => __('Awaiting shipment'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
) );
register_post_status( 'wc-verification', array(
'label' => __('Verification'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Verification <span class="count">(%s)</span>', 'Verification <span class="count">(%s)</span>' )
) );
}
// Add to list of WC Order statuses
add_filter( 'wc_order_statuses', 'add_additional_custom_statuses_to_order_statuses' );
function add_additional_custom_statuses_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-awaiting-shipment'] = __('Awaiting shipment');
$new_order_statuses['wc-verification'] = __('Verification');
}
}
return $new_order_statuses;
}
Code goes in function.php file of your active child theme (active theme). Tested and works. Rename order status from filter menu from Admin Orders list in Woocommerce
To Rename "fertiggestellt" (Completed) order status in Admin Order list order statuses tab menu use the following:
add_filter( 'gettext', 'rename_woocommerce_order_status', 10, 3 );
add_filter( 'ngettext', 'rename_woocommerce_order_status', 10, 3 );
function rename_woocommerce_order_status( $translated, $text, $domain ) {
if ( strpos($text, 'Completed') !== false ) {
$translated = str_replace('Processing', 'Custom text', $text );
}
if ( strpos($translated, 'fertiggestellt') !== false ) {
$translated = str_replace('fertiggestellt', 'Custom text', $translated );
}
return $translated;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.Update order to custom status in Woocommerce with multiple custom statuses
The Order custom status keys are too long and should be simpler and shorter, so I have revisited a bit your code, renaming your custom order statuses keys (slugs) and make it more compact:
// Utility function for custom order status data array (key/label pairs)
function get_custom_order_statuses(){
return array(
'wc-in-progress' => __('Bestellung in Bearbeitung'), // Bestellung in Bearbeitung
'wc-waiting-cancel' => __('Abbruchbestätigung ausstehend'), // Abbruchbestätigung ausstehend
'wc-finished' => __('Bestellung abgeschlossen'), // Bestellung abgeschlossen
'wc-accepted' => __('Bestellung abgenommen'), // Bestellung abgenommen
);
}
// Register custom Order statuses
add_action( 'init', 'register_custom_order_statuses' );
function register_custom_order_statuses() {
// Loop through custom order statuses array (key/label pairs)
foreach( get_custom_order_statuses() as $key => $label ) {
register_post_status( $key, array(
'label' => $label,
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( $label . ' <span class="count">(%s)</span>', $label . ' <span class="count">(%s)</span>' )
) );
}
}
// Add custom Order statuses
add_filter( 'wc_order_statuses', 'add_custom_order_statuses', 10, 1 );
function add_custom_order_statuses( $order_statuses ) {
$sorted_order_statuses = array(); // Initializing
foreach ( $order_statuses as $key => $label ) {
$sorted_order_statuses[ $key ] = $label;
if ( $key === 'wc-completed' ) {
// Loop through custom order statuses array (key/label pairs)
foreach( get_custom_order_statuses() as $custom_key => $custom_label ) {
$sorted_order_statuses[$custom_key] = $custom_label;
}
}
}
return $sorted_order_statuses;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works. Setting custom order statuses as paid in WooCommerce
What @Martin said. You have this available:
apply_filters( 'woocommerce_order_is_paid_statuses', array( 'processing', 'completed' ) );
So, you can add to it with add_filter():add_filter( 'woocommerce_order_is_paid_statuses', 'bbloomer_paid_is_paid_status' );
function bbloomer_paid_is_paid_status( $statuses ) {
$statuses[] = 'paid';
return $statuses;
}
Related Topics
PHP - Get Array Value with a Numeric Index
How to Create a PHP Function That I Can Call Without Parentheses
Sending JavaScript Object to PHP via Ajax
PHP Redirect with Http Query String Variables
What Sort Algorithm Does PHP Use
Custom Repository Class in Symfony2
Echo 'String' While Every Long Loop Iteration (Flush() Not Working)
How to Convert Emoji from Unicode in PHP
Php: How to Set Current Working Directory to Be Same as Directory Executing the Script
Capital Letters in Class Name PHP
Doctrine2 Findby Relationship Object Triggers String Conversion Error
What Are My Options to Check for Viruses on a PHP Upload
Using Moodle Create Users and Enroll Them in Courses via SQL
Docx File Type in PHP Finfo_File Is Application/Zip