Skip to content

Commit

Permalink
Merge branch 'master' into fix/1326-orders-menu-hpos
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosSynetos authored Oct 24, 2023
2 parents 82ab1fc + 19fbfd4 commit b170305
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 1 deletion.
107 changes: 107 additions & 0 deletions includes/class-wc-calypso-bridge-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -121,6 +126,108 @@ 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 ) {
$site_slug = WC_Calypso_Bridge_Instance()->get_site_slug();
$current_theme_slug = get_stylesheet();

$result['themes'] = array(
array(
'name' => 'Tsubaki',
'price' => 'Free',
'color_palettes' => array(),
'total_palettes' => 0,
'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,
),
array(
'name' => 'Tazza',
'price' => 'Free',
'color_palettes' => array(),
'total_palettes' => 0,
'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,
),
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' => '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,
),
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' => '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,
),
);

$result['_links']['browse_all']['href'] = 'https://wordpress.com/themes/' . $site_slug;

return $result;
}
}

WC_Calypso_Bridge_Filters::get_instance();
61 changes: 60 additions & 1 deletion includes/class-wc-calypso-bridge-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package WC_Calypso_Bridge/Classes
* @since 1.0.0
* @version 2.2.16
* @version x.x.x
*/

use Automattic\WooCommerce\Admin\WCAdminHelper;
Expand Down Expand Up @@ -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',
);

/**
Expand Down Expand Up @@ -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' ] );
}
}

Expand Down Expand Up @@ -651,6 +653,63 @@ 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 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 (60 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;
}

// 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 );
}, PHP_INT_MAX );

}

/**
* Prevent redirects on activation when WooCommerce is being setup. Some plugins
* do this when they are activated.
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This section describes how to install the plugin and get it working.

= Unreleashed =
* Fix the "Orders" menu position when using HPOS #1330
* Preconfigure product measurement units #xxx

= 2.2.17 =
* Enable the reactified WC Admin Marketplace under the "Extensions > Discover" menu item #1318
Expand Down

0 comments on commit b170305

Please sign in to comment.