woocommerce_rest_pre_insert_<post_type>_object

Filters an object before it is inserted via the REST API.

Description

apply_filters( 'woocommerce_rest_pre_insert_<post_type>_object', (WC_Data) $product, (WP_REST_Request) $request, (bool) $creating ); 

The dynamic portion(s) of the hook name refer refers to the object type slug.

Parameters (3)

0. $product (WC_Data)
Object object.
1. $request (WP_REST_Request)
Request object.
2. $creating (bool)
If is creating a new object.

Usage

To run the hook, copy the example below.
  1. $product = apply_filters( 'woocommerce_rest_pre_insert_{$post_type}_object', $product, $request, $creating ); 
  2.  
  3. if ( !empty( $product ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the woocommerce_rest_pre_insert_<post_type>_object callback 
  2. function filter_woocommerce_rest_pre_insert_post_type_object( $product, $request, $creating ) { 
  3. // make filter magic happen here... 
  4. return $product
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "woocommerce_rest_pre_insert_{$post_type}_object", 'filter_woocommerce_rest_pre_insert_post_type_object', 10, 3 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "woocommerce_rest_pre_insert_{$post_type}_object", 'filter_woocommerce_rest_pre_insert_post_type_object', 10, 3 ); 

Defined (5)

The filter is defined in the following location(s).

/includes/api/class-wc-rest-products-controller.php  
  1. return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating ); 
/includes/api/class-wc-rest-product-variations-controller.php  
  1. return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating ); 
/includes/api/class-wc-rest-orders-controller.php  
  1. return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating ); 
/includes/api/class-wc-rest-order-refunds-controller.php  
  1. return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $refund, $request, $creating ); 
/includes/api/class-wc-rest-coupons-controller.php  
  1. return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating );