Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active October 20, 2020 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrick1229/e90f85c0ad152e9b2260bac93f6ae962 to your computer and use it in GitHub Desktop.
Save jrick1229/e90f85c0ad152e9b2260bac93f6ae962 to your computer and use it in GitHub Desktop.
Create "Needs Approval" status and apply to orders that contain specified product ID
<?php
/*
*
* Register "Needs Approval" status
*
*/
add_filter( 'woocommerce_register_shop_order_post_statuses', 'register_needs_approval_status' );
function register_needs_approval_status( $order_statuses ){
// Status must start with "wc-"
$order_statuses['wc-needs-approval'] = array(
'label' => _x( 'Needs Approval', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Needs Approval <span class="count">(%s)</span>', 'Needs Approval <span class="count">(%s)</span>', 'woocommerce' ),
);
return $order_statuses;
}
/*
*
* Display "Needs Approval" on the admin single order page
* &&
* Display "Needs Approval" in the bulks actions menu on the admin orders page
*
*/
add_filter( 'wc_order_statuses', 'show_needs_approval_status' );
function show_needs_approval_status( $order_statuses ) {
$order_statuses['wc-needs-approval'] = _x( 'Needs Approval', 'Order status', 'woocommerce' );
return $order_statuses;
}
add_filter( 'bulk_actions-edit-shop_order', 'show_needs_approval_status_bulk' );
function show_needs_approval_status_bulk( $bulk_actions ) {
$bulk_actions['mark_needs-approval'] = 'Change status to Needs Approval';
return $bulk_actions;
}
/*
*
* Set "Needs Approval" based on product_id
* Change $product_id variable depending on product
*
*/
add_action( 'woocommerce_thankyou', 'change_to_needs_approval' );
function change_to_needs_approval( $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();
}
if ( $product_id == 696 || $product_id == 678 ) {
$order->update_status( 'needs-approval' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment