I would like to add jquery code snippet for Woocommerce checkout page for a specific product in the cart, but I'm confused on how to adapt the code to wordpress. Any ideas? Here is the code:
add_action( 'woocommerce');
function woocommerce() {
$product_id = 18; // a specific product ID you would like to check
if( WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id(
$product_id ) ) ) {
<!-- JQuery Code -->
<script type="text/javascript">
var jq = jQuery.noConflict();
jq(window).load(function(){
jq('#email').on('input', function() {
jq( "div.tip" ).show();
jq( "#h2" ).show();
});
jq('div.tip').hide();
jq( "#h2" ).hide();
});
</script>
<!-- JQuery Code -->
}
}
I would like to add jquery code snippet for Woocommerce checkout page for a specific product in the cart, but I'm confused on how to adapt the code to wordpress. Any ideas? Here is the code:
add_action( 'woocommerce');
function woocommerce() {
$product_id = 18; // a specific product ID you would like to check
if( WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id(
$product_id ) ) ) {
<!-- JQuery Code -->
<script type="text/javascript">
var jq = jQuery.noConflict();
jq(window).load(function(){
jq('#email').on('input', function() {
jq( "div.tip" ).show();
jq( "#h2" ).show();
});
jq('div.tip').hide();
jq( "#h2" ).hide();
});
</script>
<!-- JQuery Code -->
}
}
Create js file and add it to your child theme script folder. Then just add code to functions.php, example if page is checout wp_enqueue that file.
Example: https://sridharkatakam.com/how-to-load-woocommerce-css-and-js-only-on-shop-specific-pages-in-wordpress/