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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.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 4 months ago BlockTemplates 4 weeks ago EmailImprovements 1 year ago EmailPreview 4 weeks ago Emails 1 year ago ImportExport 1 year ago Logging 1 year ago Marketing 2 years ago Notes 4 weeks ago Onboarding 5 months ago Orders 4 weeks ago ProductForm 2 years ago ProductReviews 4 weeks ago RemoteFreeExtensions 4 weeks ago Schedulers 4 weeks ago Settings 2 weeks ago Suggestions 4 weeks ago WCPayPromotion 10 months ago ActivityPanels.php 3 years ago Analytics.php 4 weeks ago CategoryLookup.php 4 years ago Coupons.php 1 year ago CouponsMovedTrait.php 5 months ago CustomerEffortScoreTracks.php 7 months ago Events.php 2 months ago FeaturePlugin.php 4 months ago Homescreen.php 1 month ago Loader.php 4 weeks ago Marketing.php 1 year ago Marketplace.php 5 months ago MobileAppBanner.php 4 years ago OrderMilestoneEasterEgg.php 4 weeks ago RemoteInboxNotifications.php 3 years ago Settings.php 2 weeks ago ShippingLabelBanner.php 1 year ago ShippingLabelBannerDisplayRules.php 1 year ago SiteHealth.php 3 years ago Survey.php 4 years ago SystemStatusReport.php 1 year ago Translations.php 1 year ago WCAdminAssets.php 2 weeks ago WCAdminSharedSettings.php 1 year ago WCAdminUser.php 9 months ago WcPayWelcomePage.php 1 year ago
Homescreen.php
283 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\Features;
11 use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Shipping;
12
13 /**
14 * Contains backend logic for the homescreen feature.
15 */
16 class Homescreen {
17 /**
18 * Menu slug.
19 */
20 const MENU_SLUG = 'wc-admin';
21
22 /**
23 * Class instance.
24 *
25 * @var Homescreen instance
26 */
27 protected static $instance = null;
28
29 /**
30 * Get class instance.
31 */
32 public static function get_instance() {
33 if ( ! self::$instance ) {
34 self::$instance = new self();
35 }
36 return self::$instance;
37 }
38
39 /**
40 * Hook into WooCommerce.
41 */
42 public function __construct() {
43 add_filter( 'woocommerce_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
44 add_action( 'admin_menu', array( $this, 'register_page' ) );
45 // In WC Core 5.1 $submenu manipulation occurs in admin_menu, not admin_head. See https://github.com/woocommerce/woocommerce/pull/29088.
46 if ( version_compare( WC_VERSION, '5.1', '>=' ) ) {
47 // priority is 20 to run after admin_menu hook for woocommerce runs, so that submenu is populated.
48 add_action( 'admin_menu', array( $this, 'possibly_remove_woocommerce_menu' ) );
49 add_action( 'admin_menu', array( $this, 'update_link_structure' ), 20 );
50 } else {
51 // priority is 20 to run after https://github.com/woocommerce/woocommerce/blob/a55ae325306fc2179149ba9b97e66f32f84fdd9c/includes/admin/class-wc-admin-menus.php#L165.
52 add_action( 'admin_head', array( $this, 'update_link_structure' ), 20 );
53 }
54
55 add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) );
56
57 if ( Features::is_enabled( 'shipping-smart-defaults' ) ) {
58 add_filter(
59 'woocommerce_admin_shared_settings',
60 array( $this, 'maybe_set_default_shipping_options_on_home' ),
61 9999
62 );
63 }
64 }
65
66 /**
67 * Set free shipping in the same country as the store default
68 * Flag rate in all other countries when any of the following conditions are true
69 *
70 * - The store sells physical products, has JP and WCS installed and connected, and is located in the US.
71 * - The store sells physical products, and is not located in US/Canada/Australia/UK (irrelevant if JP is installed or not).
72 * - The store sells physical products and is located in US, but JP and WCS are not installed.
73 *
74 * @param array $settings shared admin settings.
75 * @return array
76 */
77 public function maybe_set_default_shipping_options_on_home( $settings ) {
78 if ( ! function_exists( 'get_current_screen' ) ) {
79 return $settings;
80 }
81
82 $current_screen = get_current_screen();
83
84 // Abort if it's not the homescreen.
85 if ( ! isset( $current_screen->id ) || 'woocommerce_page_wc-admin' !== $current_screen->id ) {
86 return $settings;
87 }
88
89 // Abort if we already created the shipping options.
90 $already_created = get_option( 'woocommerce_admin_created_default_shipping_zones' );
91 if ( 'yes' === $already_created ) {
92 return $settings;
93 }
94
95 $zone_count = count( \WC_Data_Store::load( 'shipping-zone' )->get_zones() );
96 if ( $zone_count ) {
97 update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' );
98 update_option( 'woocommerce_admin_reviewed_default_shipping_zones', 'yes' );
99 return $settings;
100 }
101
102 $user_skipped_obw = $settings['onboarding']['profile']['skipped'] ?? false;
103 $store_address = $settings['preloadSettings']['general']['woocommerce_store_address'] ?? '';
104 $product_types = $settings['onboarding']['profile']['product_types'] ?? array();
105 $user_has_set_store_country = $settings['onboarding']['profile']['is_store_country_set'] ?? false;
106
107 // Do not proceed if user has not filled out their country in the onboarding profiler.
108 if ( ! $user_has_set_store_country ) {
109 return $settings;
110 }
111
112 // If user skipped the obw or has not completed the store_details
113 // then we assume the user is going to sell physical products.
114 if ( $user_skipped_obw || '' === $store_address ) {
115 $product_types[] = 'physical';
116 }
117
118 if ( false === in_array( 'physical', $product_types, true ) ) {
119 return $settings;
120 }
121
122 $country_code = wc_format_country_state_string( $settings['preloadSettings']['general']['woocommerce_default_country'] )['country'];
123 $country_name = WC()->countries->get_countries()[ $country_code ] ?? null;
124
125 $is_jetpack_installed = in_array( 'jetpack', $settings['plugins']['installedPlugins'] ?? array(), true );
126 $is_wcs_installed = in_array( 'woocommerce-services', $settings['plugins']['installedPlugins'] ?? array(), true );
127
128 if (
129 ( 'US' === $country_code && $is_jetpack_installed )
130 ||
131 ( ! 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 ) )
132 ||
133 ( 'US' === $country_code && false === $is_jetpack_installed && false === $is_wcs_installed )
134 ) {
135 $zone = new \WC_Shipping_Zone();
136 $zone->set_zone_name( $country_name );
137 $zone->add_location( $country_code, 'country' );
138
139 // Method creation has no default title, use the REST API to add a title.
140 $instance_id = $zone->add_shipping_method( 'free_shipping' );
141 $request = new \WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
142 $request->set_body_params(
143 array(
144 'settings' => array(
145 'title' => 'Free shipping',
146 ),
147 )
148 );
149 rest_do_request( $request );
150
151 update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' );
152 Shipping::delete_zone_count_transient();
153 }
154
155 return $settings;
156 }
157
158 /**
159 * Adds fields so that we can store performance indicators, row settings, and chart type settings for users.
160 *
161 * @param array $user_data_fields User data fields.
162 * @return array
163 */
164 public function add_user_data_fields( $user_data_fields ) {
165 return array_merge(
166 $user_data_fields,
167 array(
168 'homepage_layout',
169 'homepage_stats',
170 'task_list_tracked_started_tasks',
171 )
172 );
173 }
174
175 /**
176 * Registers home page.
177 */
178 public function register_page() {
179 // Register a top-level item for users who cannot view the core WooCommerce menu.
180 if ( ! self::is_admin_user() ) {
181 wc_admin_register_page(
182 array(
183 'id' => 'woocommerce-home',
184 'title' => __( 'WooCommerce', 'woocommerce' ),
185 'path' => self::MENU_SLUG,
186 'capability' => 'read',
187 )
188 );
189 return;
190 }
191
192 wc_admin_register_page(
193 array(
194 'id' => 'woocommerce-home',
195 'title' => __( 'Home', 'woocommerce' ),
196 'parent' => 'woocommerce',
197 'path' => self::MENU_SLUG,
198 'order' => 0,
199 'capability' => 'read',
200 )
201 );
202 }
203
204 /**
205 * Check if the user can access the top-level WooCommerce item.
206 *
207 * @return bool
208 */
209 public static function is_admin_user() {
210 if ( ! class_exists( 'WC_Admin_Menus', false ) ) {
211 include_once WC_ABSPATH . 'includes/admin/class-wc-admin-menus.php';
212 }
213 if ( method_exists( 'WC_Admin_Menus', 'can_view_woocommerce_menu_item' ) ) {
214 return \WC_Admin_Menus::can_view_woocommerce_menu_item() || current_user_can( 'manage_woocommerce' );
215 } else {
216 // We leave this line for WC versions <= 6.2.
217 return current_user_can( 'edit_others_shop_orders' ) || current_user_can( 'manage_woocommerce' );
218 }
219 }
220
221 /**
222 * Possibly remove the WooCommerce menu item if it was purely used to access wc-admin pages.
223 */
224 public function possibly_remove_woocommerce_menu() {
225 global $menu;
226
227 if ( self::is_admin_user() ) {
228 return;
229 }
230
231 foreach ( $menu as $key => $menu_item ) {
232 if ( self::MENU_SLUG !== $menu_item[2] || 'read' !== $menu_item[1] ) {
233 continue;
234 }
235
236 unset( $menu[ $key ] );
237 }
238 }
239
240 /**
241 * Update the WooCommerce menu structure to make our main dashboard/handler
242 * the top level link for 'WooCommerce'.
243 */
244 public function update_link_structure() {
245 global $submenu;
246 // User does not have capabilities to see the submenu.
247 if ( ! current_user_can( 'manage_woocommerce' ) || empty( $submenu['woocommerce'] ) ) {
248 return;
249 }
250
251 $wc_admin_key = null;
252 foreach ( $submenu['woocommerce'] as $submenu_key => $submenu_item ) {
253 if ( self::MENU_SLUG === $submenu_item[2] ) {
254 $wc_admin_key = $submenu_key;
255 break;
256 }
257 }
258
259 if ( ! $wc_admin_key ) {
260 return;
261 }
262
263 $menu = $submenu['woocommerce'][ $wc_admin_key ];
264
265 // Move menu item to top of array.
266 unset( $submenu['woocommerce'][ $wc_admin_key ] );
267 array_unshift( $submenu['woocommerce'], $menu );
268 }
269
270 /**
271 * Preload options to prime state of the application.
272 *
273 * @param array $options Array of options to preload.
274 * @return array
275 */
276 public function preload_options( $options ) {
277 $options[] = 'woocommerce_default_homepage_layout';
278 $options[] = 'woocommerce_admin_install_timestamp';
279
280 return $options;
281 }
282 }
283