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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 / StockNotifications / Admin / SettingsController.php
woocommerce / src / Internal / StockNotifications / Admin Last commit date
Templates 4 weeks ago AdminManager.php 10 months ago ListTable.php 10 months ago MenusController.php 10 months ago NotificationCreatePage.php 10 months ago NotificationEditPage.php 4 weeks ago NotificationsPage.php 4 weeks ago SettingsController.php 10 months ago
SettingsController.php
261 lines
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace Automattic\WooCommerce\Internal\StockNotifications\Admin;
6
7 use Automattic\WooCommerce\Internal\StockNotifications\Config;
8
9 /**
10 * Settings controller for Customer Stock Notifications.
11 */
12 class SettingsController {
13
14 /**
15 * Constructor.
16 */
17 public function __construct() {
18
19 // Add a 'Customer stock notifications' section to Products settings.
20 add_filter( 'woocommerce_get_sections_products', array( $this, 'add_customer_stock_notifications_section' ), 100, 1 );
21
22 // Add the Customer Stock Notifications settings.
23 add_filter( 'woocommerce_get_settings_products', array( $this, 'add_customer_stock_notifications_settings' ), 100, 2 );
24
25 // Display admin notices about incompatible settings combinations.
26 add_action( 'admin_notices', array( $this, 'output_admin_notices' ) );
27
28 // Display and save product-level stock notifications option.
29 add_action( 'woocommerce_product_options_stock_status', array( $this, 'add_disable_stock_notifications_checkbox' ), 20 );
30 add_action( 'woocommerce_admin_process_product_object', array( $this, 'process_product_object' ) );
31 }
32
33 /**
34 * Add a 'Customer stock notifications' section to Products settings.
35 *
36 * @param array $sections Products settings sections.
37 * @return array New Products settings sections.
38 */
39 public function add_customer_stock_notifications_section( $sections ) {
40 if ( ! is_array( $sections ) ) {
41 return $sections;
42 }
43
44 $section_title = __( 'Customer stock notifications', 'woocommerce' );
45
46 // Add 'Customer stock notifications' section to the Products tab, after Inventory.
47 $inventory_index = array_search( 'inventory', array_keys( $sections ), true );
48 if ( false !== $inventory_index ) {
49 $sections = array_slice( $sections, 0, $inventory_index + 1, true ) +
50 array( 'customer_stock_notifications' => $section_title ) +
51 array_slice( $sections, $inventory_index + 1, null, true );
52 } else {
53 $sections['customer_stock_notifications'] = $section_title;
54 }
55
56 return $sections;
57 }
58
59 /**
60 * Add the Customer Stock Notifications settings.
61 *
62 * @param array $settings Original settings.
63 * @param string $section_id Settings section identifier.
64 * @return array New settings.
65 */
66 public function add_customer_stock_notifications_settings( $settings, $section_id ) {
67
68 if ( ! is_array( $settings ) ) {
69 return $settings;
70 }
71
72 if ( 'customer_stock_notifications' !== $section_id ) {
73 return $settings;
74 }
75
76 /**
77 * Filter the Customer Stock Notifications settings.
78 *
79 * @since 10.2.0
80 *
81 * @param array $default_customer_stock_notifications_settings The default Customer Stock Notifications settings.
82 */
83 $stock_notification_settings = apply_filters(
84 'woocommerce_customer_stock_notifications_settings',
85 array(
86
87 array(
88 'title' => __( 'Customer stock notifications', 'woocommerce' ),
89 'type' => 'title',
90 'desc' => '',
91 'id' => 'product_customer_stock_notifications_options',
92 ),
93
94 array(
95 'title' => __( 'Allow sign-ups', 'woocommerce' ),
96 'desc' => __( 'Let customers sign up to be notified when products in your store are restocked.', 'woocommerce' ),
97 'id' => 'woocommerce_customer_stock_notifications_allow_signups',
98 'default' => 'no',
99 'type' => 'checkbox',
100 ),
101
102 array(
103 'title' => __( 'Require double opt-in to sign up', 'woocommerce' ),
104 'desc' => __( 'To complete the sign-up process, customers must follow a verification link sent to their e-mail after submitting the sign-up form.', 'woocommerce' ),
105 'id' => 'woocommerce_customer_stock_notifications_require_double_opt_in',
106 'default' => 'no',
107 'type' => 'checkbox',
108 ),
109
110 array(
111 'title' => __( 'Delete unverified notification sign-ups after (in days)', 'woocommerce' ),
112 'desc' => __( 'Controls how long the plugin will store unverified notification sign-ups in the database. Enter zero, or leave this field empty if you would like to store expired sign-up requests indefinitey.', 'woocommerce' ),
113 'id' => 'woocommerce_customer_stock_notifications_unverified_deletions_days_threshold',
114 'default' => Config::get_unverified_deletion_days_threshold(),
115 'type' => 'number',
116 ),
117
118 array(
119 'title' => __( 'Guest sign-up', 'woocommerce' ),
120 'desc' => __( 'Customers must be logged in to sign up for stock notifications.', 'woocommerce' ),
121 'id' => 'woocommerce_customer_stock_notifications_require_account',
122 'default' => 'no',
123 'type' => 'checkbox',
124 'desc_tip' => __( 'When enabled, guests will be redirected to a login page to complete the sign-up process.', 'woocommerce' ),
125 'checkboxgroup' => 'start',
126 'hide_if_checked' => 'option',
127 ),
128
129 array(
130 'desc' => __( 'Create an account when guests sign up for stock notifications.', 'woocommerce' ),
131 'id' => 'woocommerce_customer_stock_notifications_create_account_on_signup',
132 'default' => 'no',
133 'type' => 'checkbox',
134 'checkboxgroup' => 'end',
135 'hide_if_checked' => 'yes',
136 'autoload' => true,
137 ),
138
139 array(
140 'type' => 'sectionend',
141 'id' => 'product_customer_stock_notifications_options',
142 ),
143 )
144 );
145
146 $settings = array_merge( $settings, $stock_notification_settings );
147
148 return $settings;
149 }
150
151 /**
152 * Display admin notices about incompatible settings combinations.
153 *
154 * @return void
155 */
156 public function output_admin_notices() {
157 // Only show notices on the Customer Stock Notifications settings page.
158 $screen = get_current_screen();
159 if ( ! $screen || 'woocommerce_page_wc-settings' !== $screen->id || ! isset( $_GET['section'] ) || 'customer_stock_notifications' !== $_GET['section'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
160 return;
161 }
162
163 if ( 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ) && 'yes' === get_option( 'woocommerce_customer_stock_notifications_create_account_on_signup', 'no' ) ) {
164 wp_admin_notice(
165 sprintf(
166 /* translators: %s settings page link */
167 __( 'WooCommerce is currently <a href="%s">configured</a> to create new accounts without generating passwords automatically. Guests who sign up to receive stock notifications will need to reset their password before they can log into their new account.', 'woocommerce' ),
168 esc_url( admin_url( 'admin.php?page=wc-settings&tab=account' ) )
169 ),
170 array(
171 'id' => 'message',
172 'type' => 'warning',
173 'dismissible' => false,
174 )
175 );
176 }
177
178 if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && Config::allows_signups() ) {
179 wp_admin_notice(
180 sprintf(
181 /* translators: %s settings page link */
182 __( 'WooCommerce is currently <a href="%s">configured</a> to hide out-of-stock products from your catalog. Customers will not be able sign up for back-in-stock notifications while this option is enabled.', 'woocommerce' ),
183 esc_url( admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) )
184 ),
185 array(
186 'id' => 'message',
187 'type' => 'warning',
188 'dismissible' => false,
189 )
190 );
191 }
192 }
193
194 /**
195 * Setting to allow admins disabling bis on product level.
196 *
197 * @return void
198 */
199 public function add_disable_stock_notifications_checkbox() {
200
201 if ( ! Config::allows_signups() ) {
202 return;
203 }
204
205 global $product_object;
206 if ( ! is_a( $product_object, 'WC_Product' ) ) {
207 return;
208 }
209
210 $enable_signups = 'no' !== $product_object->get_meta( Config::get_product_signups_meta_key() ) ? 'yes' : 'no';
211
212 wp_nonce_field( 'woocommerce-customer-stock-notifications-edit-product', 'customer_stock_notifications_edit_product_security' );
213 woocommerce_wp_checkbox(
214 array(
215 'id' => Config::get_product_signups_meta_key(),
216 'label' => __( 'Stock notifications', 'woocommerce' ),
217 'value' => $enable_signups,
218 'wrapper_class' => implode(
219 ' ',
220 array_map(
221 function ( $type ) {
222 return 'show_if_' . $type;
223 },
224 Config::get_supported_product_types()
225 )
226 ),
227 'description' => __( 'Let customers sign up to be notified when this product is restocked', 'woocommerce' ),
228 )
229 );
230 }
231
232 /**
233 * Save product settings meta.
234 *
235 * @param WC_Product $product The product object.
236 * @return void
237 */
238 public static function process_product_object( $product ) {
239
240 if ( ! Config::allows_signups() ) {
241 return;
242 }
243
244 if ( ! is_a( $product, 'WC_Product' ) ) {
245 return;
246 }
247
248 if ( ! $product->is_type( Config::get_supported_product_types() ) ) {
249 return;
250 }
251
252 $posted_is_enabled = isset( $_POST[ Config::get_product_signups_meta_key() ] );
253 $current_value = $product->get_meta( Config::get_product_signups_meta_key() );
254 if ( ( $posted_is_enabled && 'no' === $current_value ) || ( ! $posted_is_enabled && 'yes' === $current_value ) ) {
255 check_admin_referer( 'woocommerce-customer-stock-notifications-edit-product', 'customer_stock_notifications_edit_product_security' );
256
257 $product->update_meta_data( Config::get_product_signups_meta_key(), $posted_is_enabled ? 'yes' : 'no' );
258 }
259 }
260 }
261