WC_Helper_Subscriptions_API::activate
Activate a WooCommerce.com product. This activates the plugin/theme on the site.
Метод класса: WC_Helper_Subscriptions_API{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WC_Helper_Subscriptions_API::activate( $request );
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_Helper_Subscriptions_API::activate() WC Helper Subscriptions API::activate WC 10.3.4
public static function activate( $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'] || ! isset( $subscription['local']['active'] ) ) {
wp_send_json_error(
array(
'message' => __( 'This product is not installed.', 'woocommerce' ),
),
400
);
}
if ( true === $subscription['local']['active'] ) {
wp_send_json_success(
array(
'message' => __( 'This product is already active.', 'woocommerce' ),
),
);
}
if ( 'plugin' === $subscription['product_type'] ) {
$success = activate_plugin( $subscription['local']['path'] );
if ( is_wp_error( $success ) ) {
wp_send_json_error(
array(
'message' => __( 'There was an error activating this plugin.', 'woocommerce' ),
),
400
);
}
} elseif ( 'theme' === $subscription['product_type'] ) {
switch_theme( $subscription['local']['slug'] );
$theme = wp_get_theme();
if ( $subscription['local']['slug'] !== $theme->get_stylesheet() ) {
wp_send_json_error(
array(
'message' => __( 'There was an error activating this theme.', 'woocommerce' ),
),
400
);
}
}
wp_send_json_success(
array(
'message' => __( 'This product has been activated.', 'woocommerce' ),
),
);
}