WC_Helper::connect_theme()
Connect theme to the WCCOM.
Depending on the activated theme attempts to look through available subscriptions and auto-activate one if possible, so the user does not need to visit the Helper UI at all after installing a new extension.
Method of the class: WC_Helper{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$result = WC_Helper::connect_theme( $product_id );
- $product_id(string) (required)
- The product id of the activated theme.
WC_Helper::connect_theme() WC Helper::connect theme code WC 9.7.1
public static function connect_theme( $product_id ) { // Make sure we have a connection. $auth = WC_Helper_Options::get( 'auth' ); if ( empty( $auth ) ) { return; } wp_clean_themes_cache( false ); $themes = self::get_local_woo_themes(); $themes = array_filter( $themes, function ( $theme ) use ( $product_id ) { return $theme['_product_id'] === $product_id; } ); if ( empty( $themes ) ) { return; } $theme = reset( $themes ); $subscription = self::get_available_subscription( $product_id ); // No valid subscription found. if ( ! $subscription ) { return; } $product_key = $subscription['product_key']; list( $activation_response, $activated, $body ) = self::wccom_activate( $product_key ); if ( $activated ) { self::log( 'Auto-activated a subscription for ' . $theme['Name'] ); /** * Fires when the Helper activates a product successfully. * * @param int $product_id Product ID being activated. * @param string $product_key Subscription product key. * @param array $activation_response The response object from wp_safe_remote_request(). */ do_action( 'woocommerce_helper_subscription_activate_success', $product_id, $product_key, $activation_response ); } else { self::log( 'Could not activate a subscription for theme: ' . $theme['Name'] ); /** * Fires when the Helper fails to activate a product. * * @param int $product_id Product ID being activated. * @param string $product_key Subscription product key. * @param array $activation_response The response object from wp_safe_remote_request(). */ do_action( 'woocommerce_helper_subscription_activate_error', $product_id, $product_key, $activation_response ); } self::_flush_subscriptions_cache(); self::_flush_updates_cache(); }