/** Add shortcode to after cart button in product page**/ add_action( 'woocommerce_before_add_to_cart_button', 'misha_before_add_to_cart_btn' ); function misha_before_add_to_cart_btn(){ global $product; global $post; $terms = get_the_terms( $product->get_id(), 'product_cat'); $carArray = array(); if(is_array($terms)) { foreach($terms as $term) { $carArray[] = $term->term_id; } } $productsWithCocktails = get_field('products_with_cocktails', 'option'); $productsWithoutCocktails = get_field('products_without_cocktail', 'option'); $isWithCocktails = false; $isWithoutCocktails = false; foreach ($carArray as $item) { if (in_array($item, $productsWithCocktails)) { $isWithCocktails = true; } if (in_array($item, $productsWithoutCocktails)) { $isWithoutCocktails = true; } } if($isWithCocktails && !$isWithoutCocktails) { echo do_shortcode('[elementor-template id="75039"]'); echo ' <style> .woobt-wrap.woobt-layout-default .woobt-product-this { display: none; } button.single_add_to_cart_button { display: none !important; } button.bundle_add_to_cart_button { display: block !important; } .woobt-wrap a.woosq-link { font-size: 16px; color: #000 !important; font-weight: 400; } @media only screen and (max-width: 767px) { .woobt-wrap-responsive .woobt-products .woobt-product { flex-direction: unset !important; } } </style> '; echo do_shortcode('[woobt]').'<br>'; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter