From 44d33d743130270bfd1faa65d1ccbf51389df04d Mon Sep 17 00:00:00 2001 From: "Panos (Panagiotis) Synetos" <2484390+PanosSynetos@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:06:48 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20Preconfigure=20product=20measur?= =?UTF-8?q?ement=20units?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-wc-calypso-bridge-setup.php | 56 +++++++++++++++++++++- readme.txt | 3 ++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-calypso-bridge-setup.php b/includes/class-wc-calypso-bridge-setup.php index d7004024..aea4d121 100644 --- a/includes/class-wc-calypso-bridge-setup.php +++ b/includes/class-wc-calypso-bridge-setup.php @@ -4,7 +4,7 @@ * * @package WC_Calypso_Bridge/Classes * @since 1.0.0 - * @version 2.2.15 + * @version x.x.x */ use Automattic\WooCommerce\Admin\WCAdminHelper; @@ -50,6 +50,7 @@ public static function get_instance() { 'set_wc_tracker_default' => 'set_wc_tracker_default_callback', 'set_wc_subscriptions_siteurl' => 'set_wc_subscriptions_siteurl_callback', 'set_wc_subscriptions_siteurl_add_domain' => 'set_wc_subscriptions_siteurl_add_domain_callback', + 'set_wc_measurement_units' => 'set_wc_measurement_units_callback', ); /** @@ -142,6 +143,7 @@ public function modify_one_time_operations() { unset( $this->one_time_operations[ 'set_wc_tracker_default' ] ); unset( $this->one_time_operations[ 'set_wc_subscriptions_siteurl' ] ); unset( $this->one_time_operations[ 'set_wc_subscriptions_siteurl_add_domain' ] ); + unset( $this->one_time_operations[ 'set_wc_measurement_units' ] ); } } @@ -638,6 +640,58 @@ public function set_wc_subscriptions_siteurl_add_domain_callback() { } + /** + * Preconfigure product measurement units. + * + * @since x.x.x + */ + public function set_wc_measurement_units_callback() { + + add_action( 'plugins_loaded', function () { + + $operation = 'set_wc_measurement_units'; + + // Set the operation as completed if the store is active for more than 10 minutes. + if ( WCAdminHelper::is_wc_admin_active_for( 10 * MINUTE_IN_SECONDS ) ) { + update_option( $this->option_prefix . $operation, 'completed', 'no' ); + $this->write_to_log( $operation, 'completed (10 minutes)' ); + + return; + } + + // Bail out early if WooCommerce is not active. + if ( + ! function_exists( 'WC' ) || + ! method_exists( WC(), 'plugin_path' ) + ) { + update_option( $this->option_prefix . $operation, 'completed', 'no' ); + $this->write_to_log( $operation, 'plugin_path does not exist' ); + + return; + }; + + list( $country ) = explode( ':', get_option( 'woocommerce_default_country' ) ); + $locale_info = (array) include WC()->plugin_path() . '/i18n/locale-info.php'; + + if ( + ! isset( $locale_info[ $country ]['weight_unit'] ) || + ! isset( $locale_info[ $country ]['dimension_unit'] ) + ) { + update_option( $this->option_prefix . $operation, 'completed', 'no' ); + $this->write_to_log( $operation, 'locale_info does not exist for country ' . $country ); + + return; + } + + update_option('woocommerce_weight_unit', $locale_info[ $country ]['weight_unit']); + update_option('woocommerce_dimension_unit', $locale_info[ $country ]['dimension_unit']); + + update_option( $this->option_prefix . $operation, 'completed', 'no' ); + $this->write_to_log( $operation, 'done for country ' . $country ); + }, PHP_INT_MAX ); + + } + /** * Prevent redirects on activation when WooCommerce is being setup. Some plugins * do this when they are activated. diff --git a/readme.txt b/readme.txt index 64896331..8b42cd6f 100644 --- a/readme.txt +++ b/readme.txt @@ -22,6 +22,9 @@ This section describes how to install the plugin and get it working. == Changelog == += unreleased = +* Preconfigure product measurement units #xxx + = 2.2.15 = * Revert all page deletion and delete only WooCommerce related pages #1304 * Purge cache before creating WooCommerce related pages #1304 From 95058feea4e98105b7a4ae1dea7e51179f0b8c9f Mon Sep 17 00:00:00 2001 From: "Panos (Panagiotis) Synetos" <2484390+PanosSynetos@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:51:25 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20Convert=20foot=20to=20inches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-wc-calypso-bridge-setup.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-calypso-bridge-setup.php b/includes/class-wc-calypso-bridge-setup.php index aea4d121..62e7e2eb 100644 --- a/includes/class-wc-calypso-bridge-setup.php +++ b/includes/class-wc-calypso-bridge-setup.php @@ -651,10 +651,10 @@ public function set_wc_measurement_units_callback() { $operation = 'set_wc_measurement_units'; - // Set the operation as completed if the store is active for more than 10 minutes. - if ( WCAdminHelper::is_wc_admin_active_for( 10 * MINUTE_IN_SECONDS ) ) { + // Set the operation as completed if the store is active for more than 60 minutes. + if ( WCAdminHelper::is_wc_admin_active_for( 60 * MINUTE_IN_SECONDS ) ) { update_option( $this->option_prefix . $operation, 'completed', 'no' ); - $this->write_to_log( $operation, 'completed (10 minutes)' ); + $this->write_to_log( $operation, 'completed (60 minutes)' ); return; } @@ -683,8 +683,13 @@ public function set_wc_measurement_units_callback() { return; } - update_option('woocommerce_weight_unit', $locale_info[ $country ]['weight_unit']); - update_option('woocommerce_dimension_unit', $locale_info[ $country ]['dimension_unit']); + // Dimension unit for US/UK is foot; WooCommerce does not use foot, so we need to convert it to inches. + if ( 'foot' === $locale_info[ $country ]['dimension_unit'] ) { + $locale_info[ $country ]['dimension_unit'] = 'in'; + } + + update_option( 'woocommerce_weight_unit', $locale_info[ $country ]['weight_unit'] ); + update_option( 'woocommerce_dimension_unit', $locale_info[ $country ]['dimension_unit'] ); update_option( $this->option_prefix . $operation, 'completed', 'no' ); $this->write_to_log( $operation, 'done for country ' . $country ); From 958d348b9d6892459d7bf49d39e43ec23f516227 Mon Sep 17 00:00:00 2001 From: Chris Runnells Date: Wed, 11 Oct 2023 19:16:23 -1000 Subject: [PATCH 3/6] Add filter for get-recommended-themes API call --- includes/class-wc-calypso-bridge-filters.php | 104 +++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/includes/class-wc-calypso-bridge-filters.php b/includes/class-wc-calypso-bridge-filters.php index bd6924ff..5b9c4658 100644 --- a/includes/class-wc-calypso-bridge-filters.php +++ b/includes/class-wc-calypso-bridge-filters.php @@ -60,6 +60,11 @@ public function init() { add_filter( 'pre_option_woocommerce_merchant_email_notifications', static function() { return 'no'; } ); + + /** + * Filter recommended themes + */ + add_filter( '__experimental_woocommerce_rest_get_recommended_themes', array( $this, 'woocommerce_filter_get_recommended_themes'), 10, 3); } /** @@ -121,6 +126,105 @@ public function add_woocommerce_task_list_options_to_jetpack_sync( $allowed_opti return array_merge( $allowed_options, $woocommerce_task_list_options ); } + + /** + * Function to filter the theme recommendations for sites on WPCOM + * + * @param array $result + * @param string $industry + * @param string $currency + * @return array + */ + public function woocommerce_filter_get_recommended_themes( $result, $industry, $currency ) { + $result['themes'] = array( + array( + 'name' => 'Tsubaki', + 'price' => 'Free', + 'color_palettes' => array(), + 'total_palettes' => 0, + 'slug' => 'tsubaki', + 'is_active' => false, + 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tsubaki/screenshot.png', + 'link_url' => 'https://wordpress.com/theme/tsubaki/', + ), + array( + 'name' => 'Tazza', + 'price' => 'Free', + 'color_palettes' => array(), + 'total_palettes' => 0, + 'slug' => 'tazza', + 'is_active' => false, + 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tazza/screenshot.png', + 'link_url' => 'https://wordpress.com/theme/tazza/', + ), + array( + 'name' => 'Amulet', + 'price' => 'Free', + 'color_palettes' => array( + array( + 'title' => 'Default', + 'primary' => '#FEFBF3', + 'secondary' => '#7F7E7A', + ), + array( + 'title' => 'Brown Sugar', + 'primary' => '#EFEBE0', + 'secondary' => '#AC6239', + ), + array( + 'title' => 'Midnight', + 'primary' => '#161514', + 'secondary' => '#AFADA7', + ), + array( + 'title' => 'Olive', + 'primary' => '#FEFBF3', + 'secondary' => '#7F7E7A', + ), + ), + 'total_palettes' => 5, + 'slug' => 'amulet', + 'is_active' => false, + 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/amulet/screenshot.png', + 'link_url' => 'https://wordpress.com/theme/amulet/', + ), + array( + 'name' => 'Zaino', + 'price' => 'Free', + 'color_palettes' => array( + array( + 'title' => 'Default', + 'primary' => '#202124', + 'secondary' => '#E3CBC0', + ), + array( + 'title' => 'Aubergine', + 'primary' => '#1B1031', + 'secondary' => '#E1746D', + ), + array( + 'title' => 'Block out', + 'primary' => '#FF5252', + 'secondary' => '#252525', + ), + array( + 'title' => 'Canary', + 'primary' => '#FDFF85', + 'secondary' => '#353535', + ), + ), + 'total_palettes' => 11, + 'slug' => 'zaino', + 'is_active' => false, + 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/zaino/screenshot.png', + 'link_url' => 'https://wordpress.com/theme/zaino/', + ), + ); + + $result['_links']['browse_all']['href'] = 'https://wordpress.com/themes/'; + + return $result; + } } WC_Calypso_Bridge_Filters::get_instance(); From 9c750bf254aeb3fd1a708bc41d9081f7b185a20e Mon Sep 17 00:00:00 2001 From: Chris Runnells Date: Tue, 17 Oct 2023 12:55:26 -1000 Subject: [PATCH 4/6] Add site slug to theme URLs --- includes/class-wc-calypso-bridge-filters.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-calypso-bridge-filters.php b/includes/class-wc-calypso-bridge-filters.php index 5b9c4658..852b0781 100644 --- a/includes/class-wc-calypso-bridge-filters.php +++ b/includes/class-wc-calypso-bridge-filters.php @@ -136,6 +136,8 @@ public function add_woocommerce_task_list_options_to_jetpack_sync( $allowed_opti * @return array */ public function woocommerce_filter_get_recommended_themes( $result, $industry, $currency ) { + $site_slug = WC_Calypso_Bridge_Instance()->get_site_slug(); + $result['themes'] = array( array( 'name' => 'Tsubaki', @@ -145,7 +147,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'slug' => 'tsubaki', 'is_active' => false, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tsubaki/screenshot.png', - 'link_url' => 'https://wordpress.com/theme/tsubaki/', + 'link_url' => 'https://wordpress.com/theme/tsubaki/' . $site_slug, ), array( 'name' => 'Tazza', @@ -155,7 +157,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'slug' => 'tazza', 'is_active' => false, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tazza/screenshot.png', - 'link_url' => 'https://wordpress.com/theme/tazza/', + 'link_url' => 'https://wordpress.com/theme/tazza/' . $site_slug, ), array( 'name' => 'Amulet', @@ -186,7 +188,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'slug' => 'amulet', 'is_active' => false, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/amulet/screenshot.png', - 'link_url' => 'https://wordpress.com/theme/amulet/', + 'link_url' => 'https://wordpress.com/theme/amulet/' . $site_slug, ), array( 'name' => 'Zaino', @@ -217,11 +219,11 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'slug' => 'zaino', 'is_active' => false, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/zaino/screenshot.png', - 'link_url' => 'https://wordpress.com/theme/zaino/', + 'link_url' => 'https://wordpress.com/theme/zaino/' . $site_slug, ), ); - $result['_links']['browse_all']['href'] = 'https://wordpress.com/themes/'; + $result['_links']['browse_all']['href'] = 'https://wordpress.com/themes/' . $site_slug; return $result; } From 5c34916d94a9d985a0825ec8e1b4592783a41284 Mon Sep 17 00:00:00 2001 From: Chris Runnells Date: Tue, 17 Oct 2023 14:54:28 -1000 Subject: [PATCH 5/6] Make sure 'is_active' is set correctly --- includes/class-wc-calypso-bridge-filters.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-calypso-bridge-filters.php b/includes/class-wc-calypso-bridge-filters.php index 852b0781..dfad532a 100644 --- a/includes/class-wc-calypso-bridge-filters.php +++ b/includes/class-wc-calypso-bridge-filters.php @@ -137,6 +137,7 @@ public function add_woocommerce_task_list_options_to_jetpack_sync( $allowed_opti */ public function woocommerce_filter_get_recommended_themes( $result, $industry, $currency ) { $site_slug = WC_Calypso_Bridge_Instance()->get_site_slug(); + $current_theme_slug = get_stylesheet(); $result['themes'] = array( array( @@ -145,7 +146,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'color_palettes' => array(), 'total_palettes' => 0, 'slug' => 'tsubaki', - 'is_active' => false, + 'is_active' => $current_theme_slug === 'tsubaki', 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tsubaki/screenshot.png', 'link_url' => 'https://wordpress.com/theme/tsubaki/' . $site_slug, ), @@ -155,7 +156,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'color_palettes' => array(), 'total_palettes' => 0, 'slug' => 'tazza', - 'is_active' => false, + 'is_active' => $current_theme_slug === 'tazza', 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tazza/screenshot.png', 'link_url' => 'https://wordpress.com/theme/tazza/' . $site_slug, ), @@ -186,7 +187,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ ), 'total_palettes' => 5, 'slug' => 'amulet', - 'is_active' => false, + 'is_active' => $current_theme_slug === 'amulet', 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/amulet/screenshot.png', 'link_url' => 'https://wordpress.com/theme/amulet/' . $site_slug, ), @@ -217,7 +218,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ ), 'total_palettes' => 11, 'slug' => 'zaino', - 'is_active' => false, + 'is_active' => $current_theme_slug === 'zaino', 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/zaino/screenshot.png', 'link_url' => 'https://wordpress.com/theme/zaino/' . $site_slug, ), From 35bb9b2ad64c324ffe0454d7cbb69a81e7359391 Mon Sep 17 00:00:00 2001 From: Chris Runnells Date: Tue, 17 Oct 2023 14:59:25 -1000 Subject: [PATCH 6/6] Yoda case. --- includes/class-wc-calypso-bridge-filters.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-calypso-bridge-filters.php b/includes/class-wc-calypso-bridge-filters.php index dfad532a..f935c4e6 100644 --- a/includes/class-wc-calypso-bridge-filters.php +++ b/includes/class-wc-calypso-bridge-filters.php @@ -146,7 +146,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'color_palettes' => array(), 'total_palettes' => 0, 'slug' => 'tsubaki', - 'is_active' => $current_theme_slug === 'tsubaki', + 'is_active' => 'tsubaki' === $current_theme_slug, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tsubaki/screenshot.png', 'link_url' => 'https://wordpress.com/theme/tsubaki/' . $site_slug, ), @@ -156,7 +156,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ 'color_palettes' => array(), 'total_palettes' => 0, 'slug' => 'tazza', - 'is_active' => $current_theme_slug === 'tazza', + 'is_active' => 'tazza' === $current_theme_slug, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/tazza/screenshot.png', 'link_url' => 'https://wordpress.com/theme/tazza/' . $site_slug, ), @@ -187,7 +187,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ ), 'total_palettes' => 5, 'slug' => 'amulet', - 'is_active' => $current_theme_slug === 'amulet', + 'is_active' => 'amulet' === $current_theme_slug, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/amulet/screenshot.png', 'link_url' => 'https://wordpress.com/theme/amulet/' . $site_slug, ), @@ -218,7 +218,7 @@ public function woocommerce_filter_get_recommended_themes( $result, $industry, $ ), 'total_palettes' => 11, 'slug' => 'zaino', - 'is_active' => $current_theme_slug === 'zaino', + 'is_active' => 'zaino' === $current_theme_slug, 'thumbnail_url' => 'https://i0.wp.com/s2.wp.com/wp-content/themes/premium/zaino/screenshot.png', 'link_url' => 'https://wordpress.com/theme/zaino/' . $site_slug, ),