WC_Helper_Subscriptions_API::install_url
Get the install URL for a WooCommerce.com product.
Method of the class: WC_Helper_Subscriptions_API{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Helper_Subscriptions_API::install_url( $request );
- $request(WP_REST_Request) (required)
- Request object.
WC_Helper_Subscriptions_API::install_url() WC Helper Subscriptions API::install url code WC 10.6.2
public static function install_url( $request ) {
$product_key = $request->get_param( 'product_key' );
$subscription = WC_Helper::get_subscription( $product_key );
if ( ! $subscription ) {
wp_send_json_error(
array(
'message' => __( 'We couldn\'t find a subscription for this product.', 'woocommerce' ),
),
400
);
}
if ( true === $subscription['local']['installed'] ) {
wp_send_json_success(
array(
'message' => __( 'This product is already installed.', 'woocommerce' ),
),
);
}
$install_url = WC_Helper::get_subscription_install_url(
$subscription['product_key'],
$subscription['product_slug']
);
if ( ! $install_url ) {
wp_send_json_error(
array(
'message' => __( 'There was an error getting the install URL for this product.', 'woocommerce' ),
),
400
);
}
wp_send_json_success(
array(
'url' => $install_url,
),
);
}