Last active 1713289100

Revision 0d3055e408722be8f00b19515529d2a8aa7c54c3

deactivate-google-feed.php Raw
1add_action('woocommerce_product_options_inventory_product_data', 'add_google_feed_checkbox');
2
3function add_google_feed_checkbox() {
4 global $post;
5
6 // Get the current value of the '_google_feed_include' meta key.
7 $google_feed_include = get_post_meta($post->ID, '_google_feed_include', true);
8
9 // Convert the meta value to a boolean.
10 $checked = 'yes' === $google_feed_include; // This will be true if 'yes', false otherwise
11
12 woocommerce_wp_checkbox(array(
13 'id' => '_google_feed_include',
14 'label' => __('Google Feed', 'text-domain'),
15 'description' => __('If unchecked, this product will not show in the Google Feed.', 'text-domain'),
16 'desc_tip' => true,
17 'value' => 'yes', // The value to send when checked
18 'checked' => $checked, // The state of the checkbox (boolean)
19 ));
20}
21
22add_action('woocommerce_process_product_meta', 'save_google_feed_checkbox_value', 10, 1);
23
24function save_google_feed_checkbox_value($post_id) {
25 if (!isset($_POST['woocommerce_meta_nonce']) || !wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')) {
26 return;
27 }
28
29 $google_feed_include = isset($_POST['_google_feed_include']) && 'yes' === $_POST['_google_feed_include'] ? 'yes' : 'no';
30 update_post_meta($post_id, '_google_feed_include', $google_feed_include);
31}
32