Created
June 3, 2022 00:57
-
-
Save JoelEadeDesign/aa3f63f92949f1241177c65280ed519f to your computer and use it in GitHub Desktop.
Function to control WooCommerce Order Status by User Role
This file contains hidden or 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 | |
/* Source: https://quadlayers.com/change-order-status-automatically-in-woocommerce/ */ | |
function user_role_order_status( $order_id ) { | |
if ( ! $order_id ) { return; } | |
$order = wc_get_order( $order_id ); | |
// Change db prefix `wp_` of `wp_capabilities`, if required | |
$usermeta = get_user_meta( get_current_user_id(),'wp_capabilities', true ); | |
// Enter the user role name to apply this function to | |
if ( key( $usermeta ) === 'user_role_name_goes_here' ) { | |
// Check for order status i.e. cancelled, failed, on-hold, pending, processing, completed | |
if( 'processing'== $order->get_status() ) { | |
// Change order status i.e. cancelled, failed, on-hold, pending, processing, completed | |
$order->update_status( 'completed' ); | |
} | |
} | |
} | |
add_action( 'woocommerce_thankyou', 'user_role_order_status', 10, 1 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment