woocommerce_new_order

woocommerce_new_order

Appears in: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Hook Type: action
See hook in action

See hook in core

Displaying hooks found in version: woocommerce.8.7.0

do_action('woocommerce_new_order') is found 6 times:

  • /includes/data-stores/class-wc-order-data-store-cpt.php line 103
    		if ( '' === $order->get_order_key() ) {
    			$order->set_order_key( wc_generate_order_key() );
    		}
    		parent::create( $order );
    		do_action( 'woocommerce_new_order', $order->get_id(), $order );
    	}
    
    	/**
    	 * Read order data. Can be overridden by child classes to load other props.
    	 *
    	 * @param WC_Order $order Order object.
    
  • /includes/data-stores/class-wc-order-data-store-cpt.php line 194
    		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
    		$new_status = $order->get_status( 'edit' );
    
    		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
    			do_action( 'woocommerce_new_order', $order->get_id(), $order );
    		} else {
    			do_action( 'woocommerce_update_order', $order->get_id(), $order );
    		}
    	}
    
    	/**
    
  • /includes/legacy/api/v2/class-wc-api-orders.php line 465
     
    			wc_delete_shop_order_transients( $order );
    
    			do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this );
    			do_action( 'woocommerce_new_order', $order->get_id() );
    
    			return $this->get_order( $order->get_id() );
    		} catch ( WC_Data_Exception $e ) {
    			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) );
    		} catch ( WC_API_Exception $e ) {
    			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
    
  • /includes/legacy/api/v3/class-wc-api-orders.php line 505
     
    			wc_delete_shop_order_transients( $order );
    
    			do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this );
    			do_action( 'woocommerce_new_order', $order->get_id() );
    
    			return $this->get_order( $order->get_id() );
    		} catch ( WC_Data_Exception $e ) {
    			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) );
    		} catch ( WC_API_Exception $e ) {
    			return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
    
  • /src/Internal/DataStores/Orders/OrdersTableDataStore.php line 2420
    		 *
    		 * @param int       Order ID.
    		 * @param \WC_Order Order object.
    		 */
    		do_action( 'woocommerce_new_order', $order->get_id(), $order );
    	}
    
    	/**
    	 * Helper method responsible for persisting new data to order table.
    	 *
    	 * This should not contain and specific meta or actions, so that it can be used other order types safely.
    
  • /src/Internal/DataStores/Orders/OrdersTableDataStore.php line 2508
    		$this->clear_caches( $order );
    
    		// For backwards compatibility, moving an auto-draft order to a valid status triggers the 'woocommerce_new_order' hook.
    		if ( ! empty( $changes['status'] ) && 'auto-draft' === $previous_status ) {
    			do_action( 'woocommerce_new_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
    			return;
    		}
    
    		// For backwards compat with CPT, trashing/untrashing and changing previously datastore-level props does not trigger the update hook.
    		if ( ( ! empty( $changes['status'] ) && in_array( 'trash', array( $changes['status'], $previous_status ), true ) )
    			|| ( ! empty( $changes ) && ! array_diff_key( $changes, array_flip( $this->get_post_data_store_for_backfill()->get_internal_data_store_key_getters() ) ) ) ) {
    

See this hook used in plugins: