Automattic\WooCommerce\Internal\RestApi\Routes\V4\Products
Controller::prepare_links
Prepare links for the request.
Method of the class: Controller{}
No Hooks.
Returns
Array. Links for the given post.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_links( $product, $request );
- $product(WC_Product) (required)
- Object data.
- $request(WP_REST_Request<array<string,mixed>>) (required)
- Request object.
Controller::prepare_links() Controller::prepare links code WC 10.9.4
protected function prepare_links( $product, $request ) {
$links = parent::prepare_links( $product, $request );
if ( $product->is_type( ProductType::VARIABLE ) && $product->has_child() ) {
$links['variations'] = array();
foreach ( $product->get_children() as $variation_id ) {
$links['variations'][] = array(
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $variation_id ) ),
'embeddable' => true,
);
}
}
return $links;
}