WC_REST_Product_Variations_Controller::generate()
Generate all variations for a given product.
Метод класса: WC_REST_Product_Variations_Controller{}
Хуков нет.
Возвращает
WP_Error|WP_REST_Response
.
Использование
$WC_REST_Product_Variations_Controller = new WC_REST_Product_Variations_Controller(); $WC_REST_Product_Variations_Controller->generate( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Product_Variations_Controller::generate() WC REST Product Variations Controller::generate WC 9.2.3
public function generate( $request ) { $product_id = (int) $request['product_id']; if ( 'product' !== get_post_type( $product_id ) ) { return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); } wc_maybe_define_constant( 'WC_MAX_LINKED_VARIATIONS', 99 ); wc_set_time_limit( 0 ); $response = array(); $product = wc_get_product( $product_id ); $default_values = isset( $request['default_values'] ) ? $request['default_values'] : array(); $meta_data = isset( $request['meta_data'] ) ? $request['meta_data'] : array(); $data_store = $product->get_data_store(); $response['count'] = $data_store->create_all_product_variations( $product, Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ), $default_values, $meta_data ); if ( isset( $request['delete'] ) && $request['delete'] ) { $deleted_count = $this->delete_unmatched_product_variations( $product ); $response['deleted_count'] = $deleted_count; } $data_store->sort_all_product_variations( $product->get_id() ); return rest_ensure_response( $response ); }