I would like to rename the WooCommerce order status from "Completed" to "Order Received". I can edit the script below located in wc-order-functions.php, but I would prefer not to modify any core files or use a plugin.
Is it possible to override woocoomerce functions with scripts in child theme's functions.php file?
function wc_get_order_statuses() {
$order_statuses = array(
'wc-pending' => _x( 'Pending Payment', 'Order status', 'woocommerce' ),
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
'wc-on-hold' => _x( 'On Hold', 'Order status', 'woocommerce' ),
'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ),
'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ),
'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ),
);
return apply_filters( 'wc_order_statuses', $order_statuses );
}
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.
Update 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
Other related reference: How to create a custom order status in woocommerce
The accepted answer does a good job in most places, but the order status filter on the main order page is unaffected, as mentioned in one of the comments.
To update this you must also hook into the filter woocommerce_register_shop_order_post_statuses and update label_count like so:
// Rename order status 'Completed' to 'Order Received' in admin main view - different hook, different value than the other places
function wc_rename_order_status_type( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-completed' === $key ) {
$order_statuses['wc-completed']['label_count'] = _n_noop( 'Order Received <span class="count">(%s)</span>', 'Order Received <span class="count">(%s)</span>', 'woocommerce' );
}
}
return $order_statuses;
}
add_filter( 'woocommerce_register_shop_order_post_statuses', 'wc_rename_order_status_type' );
You will also need to update the string in the 'Bulk Actions' dropdown. Hooking into WordPress' gettext filter let's you do it, like so:
// Rename order status in the bulk actions dropdown on main order list
function rename_bulk_status( $translated_text, $untranslated_text, $domain ) {
if( is_admin()) {
if( $untranslated_text == 'Change Status To completed' )
$translated_text = __( 'Change Status To Order Received','woocommerce' );
}
return $translated_text;
}
add_filter('gettext', 'rename_bulk_status', 20, 3);
So add these to the accepted answer above so you have all 3 functions.
I had a similar wish, but for some reason Loic's solution did not work with my shop. So I want to share my simple solution.
With the free plugin LocoTranslate you can easily rename the order status for your language. If your page needs no translation (i.e. it is in English), it might still be handy.
Simply create a totally new translation file and enter only the new order status replacing the original name. All other terms are not affected by this language file, if the fields stay empty (don't forget to activate this pseudo-translation in page settings).
This way, there is a good chance that WooCommerce updates will not affect it.
Go to plugin Editor -> choose WooCommerce -> includes -> admin -> class-wc-admin-dashboard.php (Edit Line 45)
DO NOT COPY PASTE THE CONTENT FROM HERE. FIND & REPLACE
Default-----------------------
public function init() {
// Reviews Widget.
if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce Recent Reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) );
}
wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce Status', 'woocommerce' ), array( $this, 'status_widget' ) );
Edited--------------
public function init() {
// Reviews Widget.
if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce Recent Reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) );
}
wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'Shop Status', 'woocommerce' ), array( $this, 'status_widget' ) );
Related
I'm using the WC Vendors Woocommerce plugin that uses the following snippet in order to show 'Product Status' in vendors front-end dashboard:
/**
* Product status text for output on front end.
*/
public static function product_status( $status ) {
$product_status = apply_filters(
'wcv_product_status',
array(
'publish' => __( 'Online', 'wcvendors-pro' ),
'future' => __( 'Scheduled', 'wcvendors-pro' ),
'draft' => __( 'Draft', 'wcvendors-pro' ),
'pending' => __( 'Pending Approval', 'wcvendors-pro' ),
'private' => __( 'Admin Only', 'wcvendors-pro' ),
'trash' => __( 'Trash', 'wcvendors-pro' ),
)
);
return $product_status[ $status ];
} // product_status()
I have created an additional custom post status 'Refunded' and I would like to add this custom status to the existing statuses.
So I'm trying to tap into the filter 'wcv_product_status' to create a function that adds my new product status.
My coding knowledge is really poor and I'm just struggling to finish my snippet.
This is what I currently have:
add_filter( 'wcv_product_status', 'refunded_product_status' );
function refunded_product_status( $status ) {
'refunded' => __( 'Refunded', 'wcvendors-pro' );
return $status;
}
I guess I should be using the 'product_status' somewhere in my snippet, but how would I compile the whole thing together?
Any hint is really appreciated.
You've to change the existing array which you received as a parameter and return it.
add_filter( 'wcv_product_status', 'refunded_product_status', 20, 1 );
function refunded_product_status( $status ) {
$status['refunded'] = __( 'Refunded', 'wcvendors-pro' );
return $status;
}
How can I go about displaying the product 'tax status' (ie. taxable, delivery only, none) on the product list of the admin page?
I've been trying to display products as 'In Stock/Out of Stock' and 'Taxable/Not Taxable' on the product list so that I can easily determine the status of products and make changes if necessary.
I figured out how to display the Stock Status on the product list, however, when I try the same with the 'tax status', it doesn't work. I got Stock Status to display by adding the following code to functions.php. How can I have the 'Tax Status' display?
add_filter( 'manage_edit-product_columns', 'product_column_arrange' );
function product_column_arrange( $product_columns ) {
return array(
...
'is_in_stock' => 'Stock',
...
);
}
The following will display a custom column for product tax status in admin product list:
add_filter( 'manage_edit-product_columns', 'tax_status_product_column');
function tax_status_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_status'] = __( 'Tax status','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_status_product_column_content', 10, 2 );
function tax_status_product_column_content( $column, $post_id ){
if( $column == 'tax_status' ){
global $post, $product;
// Excluding variable and grouped products
if( is_a( $product, 'WC_Product' ) ) {
$args = array(
'taxable' => __( 'Taxable', 'woocommerce' ),
'shipping' => __( 'Shipping only', 'woocommerce' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' ),
);
echo $args[$product->get_tax_status()];
}
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.
Related: Add custom columns to admin products list in WooCommerce 3
This question already has answers here:
How to add custom stock status to products in WooCommerce 4+
(2 answers)
Closed 2 years ago.
On our site, we're using custom stock statuses for our products. We use the below code to achieve that, and it works, but there are some issues on variable products, where it changes back to the default status.
We want to use it on variable products, to display a main stock status for the whole product, but when we select our custom stock status, it will suddenly change it back to the standard stock status after some time. It saves the setting when we update the product, but it will eventually change it back after some time.
Here is our code, which is placed in our functions.php file. Hope you can help or point me in the right direction:
function add_custom_stock_type() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'På lager/fjernlager', 'woocommerce' ),
'bestillingsvare' => __( 'Bestillingsvare', 'woocommerce' ), // The new option !!!
'outofstock' => __( 'Ikke på lager', 'woocommerce' ),
), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
}
add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');
function save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
}
add_action('woocommerce_process_product_meta', 'save_custom_stock_status',99,1);
function woo_add_custom_general_fields_save_two( $post_id ){
// Select
$woocommerce_select = $_POST['_stock_status'];
if( !empty( $woocommerce_select ) )
update_post_meta( $post_id, '_stock_status', esc_attr( $woocommerce_select ) );
else
update_post_meta( $post_id, '_stock_status', '' );
}
function woocommerce_get_custom_availability( $data, $product ) {
switch( $product->stock_status ) {
case 'instock':
$data = array( 'availability' => __( 'På lager/fjernlager', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'bestillingsvare':
$data = array( 'availability' => __( 'Bestillingsvare', 'woocommerce' ), 'class' => 'bestillings-vare' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Ikke på lager', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
}
return $data;
}
add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 10, 2);
2019 Update:
In February 2019, WooCommerce added a filter to version 3.6.0 that allows users to add their own custom stock statuses.
Inside the function wc_get_product_stock_status_options, which defines the different stock statuses, there are 3 default built-in statuses: instock, outofstock, and onbackorder.
In order to add a custom status or remove a built-in one, you can simply use the new woocommerce_product_stock_status_options filter:
add_filter('woocommerce_product_stock_status_options', 'add_custom_stock_statuses');
function add_custom_stock_statuses($statuses) {
// Add a new status
$statuses['customstatus'] = __( 'My Custom Status', 'plugin-name' );
// Remove a built-in status
unset($statuses['onbackorder']);
return $statuses;
}
Unfortunately WooCommerce not supporting any custom stock status other than its own stock statuses - instock, outofstock & onbackorder. We can achieve the custom stock status by overriding the _stock_status meta in some cases but will not be successful in all cases (like variations update).
In the above functions, you have removed the onbackorder stock status and if particular product stock status changed to 'onbackorder', then it will not be shown. Note that this is the reason for showing 'instock' since its the first option in your select box.
If you are going to use the stock status purely for admin panel display purpose only, then you can achieve this by using the following functions.
/* add custom stock status */
function woocommerce_add_custom_stock_status() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
/* update custom status if backorder if varations updated */
$real_stock_status = get_post_meta($_REQUEST['post'], '_stock_status', true );
if($real_stock_status=="onbackorder") {
$stock_status = get_post_meta($_REQUEST['post'], '_custom_stock_status', true ); //get status from custom meta
update_post_meta($_REQUEST['post'], '_stock_status', wc_clean( $stock_status ));
}
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'På lager/fjernlager', 'woocommerce' ),
'bestillingsvare' => __( 'Bestillingsvare', 'woocommerce' ), // The new option !!!
'outofstock' => __( 'Ikke på lager', 'woocommerce' ),
), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
}
add_action('woocommerce_product_options_stock_status', 'woocommerce_add_custom_stock_status');
/* save custom stock status */
function woocommerce_save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
update_post_meta( $product_id, '_custom_stock_status', wc_clean( $_POST['_stock_status'] ) ); //save another custom meta since '_stock_status' will be overridden
}
add_action('woocommerce_process_product_meta', 'woocommerce_save_custom_stock_status',99,1);
/* get custom stock status */
function get_custom_stock_status( $data, $product ) {
switch( $product->stock_status ) {
case 'instock':
$data = array( 'availability' => __( 'På lager/fjernlager', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'bestillingsvare':
$data = array( 'availability' => __( 'Bestillingsvare', 'woocommerce' ), 'class' => 'bestillings-vare' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Ikke på lager', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
}
return $data;
}
add_action('woocommerce_get_availability', 'get_custom_stock_status', 10, 2);
/* change custom stock status after order completion */
function woocommerce_order_change_custom_stock_status( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
$real_stock_status = get_post_meta($product_id, '_stock_status', true );
if($real_stock_status=="onbackorder") {
$stock_status = get_post_meta($product_id, '_custom_stock_status', true ); //get status from custom meta
update_post_meta($product_id, '_stock_status', wc_clean( $stock_status ));
}
}
}
add_action( 'woocommerce_thankyou', 'woocommerce_order_change_custom_stock_status', 10, 1 );
Hope this helps.
I'm trying to rename multiple WooCommerce order status by editing my theme's functions.php file. I found some code posted here a couple years ago that works to change a single order status, but since I'm very inexperienced with php, I don't know how to expand on it to change multiple statuses. Ideally I'd also like to rename 'wc-processing' to 'Paid' and 'wc-on-hold' to 'Pending'.
Here's the code I found to edit a single order status:
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-completed' === $key ) {
$order_statuses['wc-completed'] = _x( 'Order Received', 'Order status', 'woocommerce' );
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
Anyone know what changes I need to make to change additional statuses?
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
I just create a custom status 'tree'('waiting in tree' - labeled) for my orders with the help of Custom Order Status for WooCommerce plugin.
When the user successfully completed the payment the status will change from 'pending' to 'tree'.After some process, I will change the status to processing, at the time I need to send the processing mail to the user. How can I do this, I just find the above code to register the email.
function so_27112461_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_tree_to_processing';
return $actions;
}
add_filter( 'woocommerce_email_actions', 'so_27112461_woocommerce_email_actions' );
But How can i trigger the processing mail.
The plugin your are using is kind of outdated (not updated since WooCommerce 3 release).
You don't need any plugin to do what you want, just this few hooked functions below:
// Add custom status to order list
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-tree', array(
'label' => _x( 'Waiting in tree', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Waiting in tree <span class="count">(%s)</span>', 'Waiting in tree <span class="count">(%s)</span>', 'woocommerce' )
) );
}
// Add custom status to order page drop down
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-tree'] = _x( 'Waiting in tree', 'Order status', 'woocommerce' );
return $order_statuses;
}
// Adding custom status 'tree' to admin order list bulk 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_tree'] = __( 'Mark Waiting in tree', 'woocommerce' );
return $actions;
}
// Enable the action
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-tree';
return $actions;
}
// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action('woocommerce_order_status_changed', 'custom_status_email_notifications', 20, 4 );
function custom_status_email_notifications( $order_id, $old_status, $new_status, $order ){
if ( $old_status == 'tree' && $new_status == 'processing' ) {
// Get all WC_Email instance objects
$wc_emails = WC()->mailer()->get_emails();
// Sending Customer Processing Order email notification
$wc_emails['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and Works.