Utoljára aktív 1713289100

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