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.0.1 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6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c.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / Homescreen.php
woocommerce / src / Internal / Admin Last commit date
Agentic 6 months ago EmailImprovements 1 year ago EmailPreview 1 month ago Emails 2 weeks ago ImportExport 1 year ago Logging 2 weeks ago Marketing 2 years ago Notes 2 weeks ago Onboarding 2 weeks ago Orders 1 month ago ProductForm 2 years ago ProductReviews 2 months ago RemoteFreeExtensions 2 months ago Reports 2 weeks ago Schedulers 2 weeks ago Settings 2 weeks ago Suggestions 2 weeks ago WCPayPromotion 1 year ago ActivityPanels.php 4 years ago Analytics.php 2 weeks ago CategoryLookup.php 4 years ago Coupons.php 2 weeks ago CouponsMovedTrait.php 7 months ago CustomerEffortScoreTracks.php 9 months ago Events.php 2 weeks ago FeaturePlugin.php 2 weeks ago Homescreen.php 2 weeks ago Loader.php 1 month ago Marketing.php 1 year ago Marketplace.php 7 months ago MobileAppBanner.php 4 years ago OrderMilestoneEasterEgg.php 2 months ago RemoteInboxNotifications.php 2 weeks ago Settings.php 2 weeks ago ShippingLabelBanner.php 1 year ago ShippingLabelBannerDisplayRules.php 1 year ago SiteHealth.php 2 weeks ago Survey.php 4 years ago SystemStatusReport.php 2 weeks ago TaxSettingsRecommendations.php 1 month ago Translations.php 1 year ago WCAdminAssets.php 1 week ago WCAdminSharedSettings.php 1 year ago WCAdminUser.php 10 months ago WcPayWelcomePage.php 1 year ago
Homescreen.php
280 lines
1 <?php
2 /**
3 * WooCommerce Homescreen.
4 */
5
6 declare( strict_types=1 );
7
8 namespace Automattic\WooCommerce\Internal\Admin;
9
10 use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Shipping;
11
12 /**
13 * Contains backend logic for the homescreen feature.
14 */
15 class Homescreen {
16 /**
17 * Menu slug.
18 */
19 const MENU_SLUG = 'wc-admin';
20
21 /**
22 * Class instance.
23 *
24 * @var Homescreen instance
25 */
26 protected static $instance = null;
27
28 /**
29 * Get class instance.
30 */
31 public static function get_instance() {
32 if ( ! self::$instance ) {
33 self::$instance = new self();
34 }
35 return self::$instance;
36 }
37
38 /**
39 * Hook into WooCommerce.
40 */
41 public function __construct() {
42 add_filter( 'woocommerce_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
43 add_action( 'admin_menu', array( $this, 'register_page' ) );
44 // In WC Core 5.1 $submenu manipulation occurs in admin_menu, not admin_head. See https://github.com/woocommerce/woocommerce/pull/29088.
45 if ( version_compare( WC_VERSION, '5.1', '>=' ) ) {
46 // priority is 20 to run after admin_menu hook for woocommerce runs, so that submenu is populated.
47 add_action( 'admin_menu', array( $this, 'possibly_remove_woocommerce_menu' ) );
48 add_action( 'admin_menu', array( $this, 'update_link_structure' ), 20 );
49 } else {
50 // priority is 20 to run after https://github.com/woocommerce/woocommerce/blob/a55ae325306fc2179149ba9b97e66f32f84fdd9c/includes/admin/class-wc-admin-menus.php#L165.
51 add_action( 'admin_head', array( $this, 'update_link_structure' ), 20 );
52 }
53
54 add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) );
55
56 add_filter(
57 'woocommerce_admin_shared_settings',
58 array( $this, 'maybe_set_default_shipping_options_on_home' ),
59 9999
60 );
61 }
62
63 /**
64 * Set free shipping in the same country as the store default
65 * Flag rate in all other countries when any of the following conditions are true
66 *
67 * - The store sells physical products, has JP and WCS installed and connected, and is located in the US.
68 * - The store sells physical products, and is not located in US/Canada/Australia/UK (irrelevant if JP is installed or not).
69 * - The store sells physical products and is located in US, but JP and WCS are not installed.
70 *
71 * @param array $settings shared admin settings.
72 * @return array
73 */
74 public function maybe_set_default_shipping_options_on_home( $settings ) {
75 if ( ! function_exists( 'get_current_screen' ) ) {
76 return $settings;
77 }
78
79 $current_screen = get_current_screen();
80
81 // Abort if it's not the homescreen.
82 if ( ! isset( $current_screen->id ) || 'woocommerce_page_wc-admin' !== $current_screen->id ) {
83 return $settings;
84 }
85
86 // Abort if we already created the shipping options.
87 $already_created = get_option( 'woocommerce_admin_created_default_shipping_zones' );
88 if ( 'yes' === $already_created ) {
89 return $settings;
90 }
91
92 $zone_count = count( \WC_Data_Store::load( 'shipping-zone' )->get_zones() );
93 if ( $zone_count ) {
94 update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' );
95 update_option( 'woocommerce_admin_reviewed_default_shipping_zones', 'yes' );
96 return $settings;
97 }
98
99 $user_skipped_obw = $settings['onboarding']['profile']['skipped'] ?? false;
100 $store_address = $settings['preloadSettings']['general']['woocommerce_store_address'] ?? '';
101 $product_types = $settings['onboarding']['profile']['product_types'] ?? array();
102 $user_has_set_store_country = $settings['onboarding']['profile']['is_store_country_set'] ?? false;
103
104 // Do not proceed if user has not filled out their country in the onboarding profiler.
105 if ( ! $user_has_set_store_country ) {
106 return $settings;
107 }
108
109 // If user skipped the obw or has not completed the store_details
110 // then we assume the user is going to sell physical products.
111 if ( $user_skipped_obw || '' === $store_address ) {
112 $product_types[] = 'physical';
113 }
114
115 if ( false === in_array( 'physical', $product_types, true ) ) {
116 return $settings;
117 }
118
119 $country_code = wc_format_country_state_string( $settings['preloadSettings']['general']['woocommerce_default_country'] )['country'];
120 $country_name = WC()->countries->get_countries()[ $country_code ] ?? null;
121
122 $is_jetpack_installed = in_array( 'jetpack', $settings['plugins']['installedPlugins'] ?? array(), true );
123 $is_wcs_installed = in_array( 'woocommerce-services', $settings['plugins']['installedPlugins'] ?? array(), true );
124
125 if (
126 ( 'US' === $country_code && $is_jetpack_installed )
127 ||
128 ( ! in_array( $country_code, array( 'US', 'CA', 'AU', 'NZ', 'SG', 'HK', 'GB', 'ES', 'IT', 'DE', 'FR', 'MX', 'CO', 'CL', 'AR', 'PE', 'BR', 'UY', 'GT', 'NL', 'AT', 'BE' ), true ) )
129 ||
130 ( 'US' === $country_code && false === $is_jetpack_installed && false === $is_wcs_installed )
131 ) {
132 $zone = new \WC_Shipping_Zone();
133 $zone->set_zone_name( $country_name );
134 $zone->add_location( $country_code, 'country' );
135
136 // Method creation has no default title, use the REST API to add a title.
137 $instance_id = $zone->add_shipping_method( 'free_shipping' );
138 $request = new \WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
139 $request->set_body_params(
140 array(
141 'settings' => array(
142 'title' => 'Free shipping',
143 ),
144 )
145 );
146 rest_do_request( $request );
147
148 update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' );
149 Shipping::delete_zone_count_transient();
150 }
151
152 return $settings;
153 }
154
155 /**
156 * Adds fields so that we can store performance indicators, row settings, and chart type settings for users.
157 *
158 * @param array $user_data_fields User data fields.
159 * @return array
160 */
161 public function add_user_data_fields( $user_data_fields ) {
162 return array_merge(
163 $user_data_fields,
164 array(
165 'homepage_layout',
166 'homepage_stats',
167 'task_list_tracked_started_tasks',
168 )
169 );
170 }
171
172 /**
173 * Registers home page.
174 */
175 public function register_page() {
176 // Register a top-level item for users who cannot view the core WooCommerce menu.
177 if ( ! self::is_admin_user() ) {
178 wc_admin_register_page(
179 array(
180 'id' => 'woocommerce-home',
181 'title' => __( 'WooCommerce', 'woocommerce' ),
182 'path' => self::MENU_SLUG,
183 'capability' => 'read',
184 )
185 );
186 return;
187 }
188
189 wc_admin_register_page(
190 array(
191 'id' => 'woocommerce-home',
192 'title' => __( 'Home', 'woocommerce' ),
193 'parent' => 'woocommerce',
194 'path' => self::MENU_SLUG,
195 'order' => 0,
196 'capability' => 'read',
197 )
198 );
199 }
200
201 /**
202 * Check if the user can access the top-level WooCommerce item.
203 *
204 * @return bool
205 */
206 public static function is_admin_user() {
207 if ( ! class_exists( 'WC_Admin_Menus', false ) ) {
208 include_once WC_ABSPATH . 'includes/admin/class-wc-admin-menus.php';
209 }
210 if ( method_exists( 'WC_Admin_Menus', 'can_view_woocommerce_menu_item' ) ) {
211 return \WC_Admin_Menus::can_view_woocommerce_menu_item() || current_user_can( 'manage_woocommerce' );
212 } else {
213 // We leave this line for WC versions <= 6.2.
214 return current_user_can( 'edit_others_shop_orders' ) || current_user_can( 'manage_woocommerce' );
215 }
216 }
217
218 /**
219 * Possibly remove the WooCommerce menu item if it was purely used to access wc-admin pages.
220 */
221 public function possibly_remove_woocommerce_menu() {
222 global $menu;
223
224 if ( self::is_admin_user() ) {
225 return;
226 }
227
228 foreach ( $menu as $key => $menu_item ) {
229 if ( self::MENU_SLUG !== $menu_item[2] || 'read' !== $menu_item[1] ) {
230 continue;
231 }
232
233 unset( $menu[ $key ] );
234 }
235 }
236
237 /**
238 * Update the WooCommerce menu structure to make our main dashboard/handler
239 * the top level link for 'WooCommerce'.
240 */
241 public function update_link_structure() {
242 global $submenu;
243 // User does not have capabilities to see the submenu.
244 if ( ! current_user_can( 'manage_woocommerce' ) || empty( $submenu['woocommerce'] ) ) {
245 return;
246 }
247
248 $wc_admin_key = null;
249 foreach ( $submenu['woocommerce'] as $submenu_key => $submenu_item ) {
250 if ( self::MENU_SLUG === $submenu_item[2] ) {
251 $wc_admin_key = $submenu_key;
252 break;
253 }
254 }
255
256 if ( ! $wc_admin_key ) {
257 return;
258 }
259
260 $menu = $submenu['woocommerce'][ $wc_admin_key ];
261
262 // Move menu item to top of array.
263 unset( $submenu['woocommerce'][ $wc_admin_key ] );
264 array_unshift( $submenu['woocommerce'], $menu );
265 }
266
267 /**
268 * Preload options to prime state of the application.
269 *
270 * @param array $options Array of options to preload.
271 * @return array
272 */
273 public function preload_options( $options ) {
274 $options[] = 'woocommerce_default_homepage_layout';
275 $options[] = 'woocommerce_admin_install_timestamp';
276
277 return $options;
278 }
279 }
280