Adding From,To and Message fields in cart page before checkout.I have added some code in cart.php file but after adding that code the cart page is displaying blank.

Cart.php

In cart.php i have added this code after ending this line of code ('woocommerce_after_cart_contents')

<?php add_action('woocommerce_cart_collaterals', 
 'order_comments_custom_cart_field');?>
 <?php
 function order_comments_custom_cart_field() {
  echo '<div id="cart_order_notes">';
  }
 ?>
 <div class="customer_notes_on_cart">
<label for="customer_notes_text"><?php _e('Order notes','woocommerce'); ?> 
</label>
<textarea id="customer_notes_text"></textarea>
</div>
 <form id="checkout_form" method="POST" action="<?php echo $checkout_url; ? 
>">
<input type="hidden" name="customer_notes" id="customer_notes" value="">
<a  href="#" onclick="document.getElementById('customer_notes').value=document.getElementById('customer_notes_text').value;document.getElementById('checkout_form').submit()" class="checkout-button button alt wc-forward">
<?php _e( 'Proceed to checkout', 'woocommerce' ); ?></a>
</form>

In Checkout.php i have added this code after (woocommerce_checkout_before_customer_details)

 <?php
 }
 // getting the values in checkout again
 add_action('woocommerce_checkout_before_customer_details',function(){
  ?>
 <script>
jQuery( document ).ready(function() {
jQuery('#order_comments' ).val("<?php echo 
sanitize_text_field($_POST['customer_notes']); ?>");
 });
</script>
<?php });

If i add this code in Checkout.php page it is getting blank checkout page.Tried with this but unable to get solution.Can any one help what was the issue in this.

enter image description here

  • where you place Adding order notes? means which location or page – vikrant zilpe Nov 29 at 11:31
  • @vikrantzilpe want to place order notes in cart page once i click on view cart this option need to be displayed – tester Nov 29 at 11:33
  • ok i find solution and replay you – vikrant zilpe Nov 29 at 11:35
  • @vikrantzilpe added image for clear understanding need to display in cart page below update cart – tester Nov 29 at 11:35
  • @vikrantzilpe i want to add both from and to fields as well along with message field – tester Nov 29 at 11:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.