最后活跃于 1713289100

Malin 修订了这个 Gist 1713289100. 跳至此修订

1 file changed, 1 insertion

deactivate-google-feed.php

@@ -1,3 +1,4 @@
1 + // custom QRh Feed check - not working correctly
1 2 add_action('woocommerce_product_options_inventory_product_data', 'add_google_feed_checkbox');
2 3
3 4 function add_google_feed_checkbox() {

Malin 修订了这个 Gist 1713288993. 跳至此修订

1 file changed, 31 insertions

deactivate-google-feed.php(file created)

@@ -0,0 +1,31 @@
1 + add_action('woocommerce_product_options_inventory_product_data', 'add_google_feed_checkbox');
2 +
3 + function 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 +
22 + add_action('woocommerce_process_product_meta', 'save_google_feed_checkbox_value', 10, 1);
23 +
24 + function 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 + }
更新 更早