deactivate-google-feed.php
· 1.4 KiB · PHP
Bruto
// custom QRh Feed check - not working correctly
add_action('woocommerce_product_options_inventory_product_data', 'add_google_feed_checkbox');
function add_google_feed_checkbox() {
global $post;
// Get the current value of the '_google_feed_include' meta key.
$google_feed_include = get_post_meta($post->ID, '_google_feed_include', true);
// Convert the meta value to a boolean.
$checked = 'yes' === $google_feed_include; // This will be true if 'yes', false otherwise
woocommerce_wp_checkbox(array(
'id' => '_google_feed_include',
'label' => __('Google Feed', 'text-domain'),
'description' => __('If unchecked, this product will not show in the Google Feed.', 'text-domain'),
'desc_tip' => true,
'value' => 'yes', // The value to send when checked
'checked' => $checked, // The state of the checkbox (boolean)
));
}
add_action('woocommerce_process_product_meta', 'save_google_feed_checkbox_value', 10, 1);
function save_google_feed_checkbox_value($post_id) {
if (!isset($_POST['woocommerce_meta_nonce']) || !wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')) {
return;
}
$google_feed_include = isset($_POST['_google_feed_include']) && 'yes' === $_POST['_google_feed_include'] ? 'yes' : 'no';
update_post_meta($post_id, '_google_feed_include', $google_feed_include);
}
1 | // custom QRh Feed check - not working correctly |
2 | add_action('woocommerce_product_options_inventory_product_data', 'add_google_feed_checkbox'); |
3 | |
4 | function 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 | |
23 | add_action('woocommerce_process_product_meta', 'save_google_feed_checkbox_value', 10, 1); |
24 | |
25 | function 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 |