Guest User

Untitled

a guest
Nov 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. <?php
  2. /**
  3. * Auto Complete all WooCommerce orders of a specific product.
  4. */
  5. add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
  6. function custom_woocommerce_auto_complete_order( $order_id ) {
  7. if ( ! $order_id ) {
  8. return;
  9. }
  10.  
  11. $order = wc_get_order( $order_id );
  12.  
  13. foreach ( $order->get_items() as $item_id => $item_values ) {
  14.  
  15. $product_id = $item_values->get_product_id();
  16.  
  17. if ( $product_id == 326 ) {
  18. $order->update_status( 'completed' );
  19. return;
  20. }
  21. }
  22. }
Add Comment
Please, Sign In to add comment