I managed to use tags to remove options from the drop down or the entire container; here is my code
Snippet
function enqueue_custom_js_on_product_page() {
if ( is_product() ) {
wp_enqueue_script( ‘custom-js’, get_stylesheet_directory_uri() . ‘/custom.js’, array( ‘jquery’ ), null, true );
// Get the product tags
global $post;
$terms = get_the_terms( $post->ID, ‘product_tag’ );
$tag_ids = array();
// Collect all tag IDs
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$tag_ids[] = $term->term_id;
}
}
// Pass the tag IDs to JavaScript
wp_localize_script( ‘custom-js’, ‘productData’, array(
‘tag_ids’ => $tag_ids,
));
}
}
add_action( ‘wp_enqueue_scripts’, ‘enqueue_custom_js_on_product_page’ );
And my custom.js
jQuery(document).ready(function($) {
// Log the tag IDs to the console
// console.log(“Product Tag IDs:”, productData.tag_ids);
// Remove the third option if the product has tag ID 841
if (productData.tag_ids.includes(841)) {
jQuery(‘.wc-pao-addon-field.wc-pao-addon-select’).each(function(){
jQuery(this).find(‘option:eq(2)’).remove(); // Remove the third option
});
// Remove the entire wc-pao-addons-container div
jQuery(‘.wc-pao-addons-container’).remove();
// Remove the wc-pao-col1 div
jQuery(‘.wc-pao-col1’).remove();
}
// Always remove the first option
jQuery(‘.wc-pao-addon-field.wc-pao-addon-select’).each(function(){
jQuery(this).find(‘option:first’).remove(); // Remove the first option
});
yes please!!!! this has been asked for many times for years but it hasn’t been done. This would be very helpful! or the ability to selectively disable Global Add-ons on a product by product basis so that multiple product categories wouldn’t have to be made.. it gets messy when you have to make all these product categories and you don’t want them displayed publicly.
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.
I managed to use tags to remove options from the drop down or the entire container; here is my code
Snippet
function enqueue_custom_js_on_product_page() {
if ( is_product() ) {
wp_enqueue_script( ‘custom-js’, get_stylesheet_directory_uri() . ‘/custom.js’, array( ‘jquery’ ), null, true );
// Get the product tags
global $post;
$terms = get_the_terms( $post->ID, ‘product_tag’ );
$tag_ids = array();
// Collect all tag IDs
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$tag_ids[] = $term->term_id;
}
}
// Pass the tag IDs to JavaScript
wp_localize_script( ‘custom-js’, ‘productData’, array(
‘tag_ids’ => $tag_ids,
));
}
}
add_action( ‘wp_enqueue_scripts’, ‘enqueue_custom_js_on_product_page’ );
And my custom.js
jQuery(document).ready(function($) {
// Log the tag IDs to the console
// console.log(“Product Tag IDs:”, productData.tag_ids);
// Remove the third option if the product has tag ID 841
if (productData.tag_ids.includes(841)) {
jQuery(‘.wc-pao-addon-field.wc-pao-addon-select’).each(function(){
jQuery(this).find(‘option:eq(2)’).remove(); // Remove the third option
});
// Remove the entire wc-pao-addons-container div
jQuery(‘.wc-pao-addons-container’).remove();
// Remove the wc-pao-col1 div
jQuery(‘.wc-pao-col1’).remove();
}
// Always remove the first option
jQuery(‘.wc-pao-addon-field.wc-pao-addon-select’).each(function(){
jQuery(this).find(‘option:first’).remove(); // Remove the first option
});
});
It would also be nice to be able to apply or disable on individual products.
This plugin for custom tabs has a great way of doing it. You can set them globally, but then decide to override them at the product level.
https://yikesplugins.com/plugin/custom-product-tabs-pro/
yes please!!!! this has been asked for many times for years but it hasn’t been done. This would be very helpful! or the ability to selectively disable Global Add-ons on a product by product basis so that multiple product categories wouldn’t have to be made.. it gets messy when you have to make all these product categories and you don’t want them displayed publicly.