0

I need to create a new customer order status of "pending-wholesale" when the order is created by a customer with the user role of "wholesale-customer", which we have created through the "WooCommerce Wholesale Suite" plugin. I've got a good snippet for creating the new order statuses, I just don't know how to filter their application.

1

You can use folloeing code to register you custm status and change it when specific user ordered the product:

    function register_awaiting_shipment_order_status() {
register_post_status( 'wc-pendingwholesale', 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>' ),
) );
    }
    add_action( 'init', 'register_awaiting_shipment_order_status' );

   // Add to list of WC Order statuses
   function add_awaiting_shipment_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;
    $new_order_statuses['wc-pendingwholesale'] = 'Awaiting shipment';
}

return $new_order_statuses;
  }
  add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

  add_action( 'woocommerce_order_status_changed', 'status_changed_processsing_weighted' );
  function status_changed_processsing_weighted( $order_id, $checkout = null ) {
  global $woocommerce;
  $order = new WC_Order( $order_id );

  $usermeta = get_user_meta( get_current_user_id() ,'wp_capabilities' ,true );
  if ( key( $usermeta ) === 'wholesale_customer' ) {
        $order->update_status( 'pendingwholesale', 'order_note' );
  }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.