I noticed while I was adding some custom code to my site that every time that code block ran, it made a duplicated but empty Toolset Woocommerce Field Group, resulting in the same issue from this older post: https://toolset.com/forums/topic/multiple-empty-field-groups-appeared-out-of-the-blue/
I was able to go in and delete the duplicates in phpmyadmin but wanted to see if anyone knows why this bit of code would have caused it?
I am trying to: Trigger a change to a custom field for the product CPT when the stock value changes to out of stock
Using this hook: lien caché
I created a checkbox field for products to be marked as "discontinued" and this checkbox is a field within my "additional product details" field group that shows on all woocommerce products.
What I wanted to create was a function that would run every time a product changed to out of stock. Each time an out of stock notification triggered, if the wpcf-discontinued-product was checked, then change the product visibility to exclude from catalog.
//Once a discontinued product goes out of stock, change visibility to hidden
//
function hide_if_discontinued_no_stock( $wc_get_product ) {
$is_discontinued = get_post_meta( $post_ID, 'wpcf-discontinued-product', false );
if ( $is_discontinued = 1 ){
$terms = array( 'exclude-from-catalog' ); // still show when searched for
wp_set_post_terms( $prod_ID, $terms, 'product_visibility', false );
}
}
add_action( 'woocommerce_no_stock', 'hide_if_discontinued_no_stock', 10, 1 );
I added the above code and then went to test it by editing products in the wp admin and noticed all these Toolset Woocommerce Field Groups showing up. I deleted the code, tested again, it went away. I re-added the code, more Toolset Woocommerce Field Groups. I have no idea why that code would have triggered it.