0

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 -->

   }
}

1 Answer 1

0

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.