WC_REST_Product_Variations_V2_Controller::check_variation_parent
Checks that a variation belongs to the specified parent product.
Method of the class: WC_REST_Product_Variations_V2_Controller{}
No Hooks.
Returns
true|false. TRUE if variation and parent product exist. FALSE otherwise.
Usage
// protected - for code of main (parent) or child class $result = $this->check_variation_parent( $variation_id, $parent_id ): bool;
- $variation_id(int) (required)
- Variation ID.
- $parent_id(int) (required)
- Parent product ID to check against.
Changelog
| Since 9.2.0 | Introduced. |
WC_REST_Product_Variations_V2_Controller::check_variation_parent() WC REST Product Variations V2 Controller::check variation parent code WC 10.3.6
protected function check_variation_parent( int $variation_id, int $parent_id ): bool {
$variation = $this->get_object( $variation_id );
if ( ! $variation || $parent_id !== $variation->get_parent_id() ) {
return false;
}
$parent = wc_get_product( $variation->get_parent_id() );
if ( ! $parent ) {
return false;
}
return true;
}