Home › Forums › Ticket Products › Event Tickets Plus › WooCommerce cart update quantity field
- This topic has 3 replies, 2 voices, and was last updated 8 years, 6 months ago by
Ryan Purves.
-
AuthorPosts
-
September 22, 2017 at 4:32 pm #1353705
Ryan Purves
ParticipantI found a forum post which showed a code snippet on how to disable the cart update quantity field because he had ticket meta fields that WooCommerce would not see. I used the code and it worked great, except when I applied a coupon it invalidated the code. I am only basically familar with the hooks and functions that are used and don’t have the knowledge to troubleshoot this. Is it a simple fix? The snippet is below:
/** * Make WooCommerce cart Quantity input field non-editable (readonly) ONLY FOR Event Tickets Plus products * * By Matt B and Cliff P * * From https://gist.github.com/cliffordp/66bf05df61ee269c60ff20d6f39e2cab */ function cliff_etplus_woo_cart_quantity_readonly() { if ( ! class_exists( 'Tribe__Tickets_Plus__Commerce__WooCommerce__Main' ) ) { return; } $args = array( 'post_type' => 'product', 'fields' => 'ids', 'meta_query' => array( array( 'key' => Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance()->event_key, 'value' => 0, 'compare' => '>', ), ), ); $product_ids_readonly = get_posts( $args ); $product_ids_readonly = array_unique( $product_ids_readonly ); if ( ! count( $product_ids_readonly ) ) { return; } wp_enqueue_script( 'jquery' ); ?> <script> jQuery( function( $ ) { var product_ids = <?php echo json_encode( $product_ids_readonly ); ?>; var $remove_links = $( 'body.woocommerce-cart .woocommerce tr.cart_item td.product-remove a' ); $remove_links.each( function() { var product_id = parseInt( $( this ).data( 'product_id' ), 10 ); if ( -1 === $.inArray( product_id, product_ids ) ) { return; } var $row = $( this ).closest( 'tr' ); $row.find( 'td.product-quantity input' ).attr( 'readonly', true ); } ); } ); </script> <?php } add_action( 'wp_head', 'cliff_etplus_woo_cart_quantity_readonly' );September 25, 2017 at 1:48 pm #1354530Cliff
MemberHi, Ryan.
Thanks for sharing your experience with https://gist.github.com/cliffordp/66bf05df61ee269c60ff20d6f39e2cab
Such snippets aren’t perfect for everyone but may be useful in some cases.
Discovering that this does not work after the cart’s refresh is disappointing, but we cannot guarantee it, and I don’t have a quick solution for you.
If you want all of the WooCommerce Products’ quantities to be read-only (say if you only sell tickets to events and not anything else), you might be able to accomplish that a bit more easily.
Please let me know how this goes for you.
October 17, 2017 at 9:37 am #1364728Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘WooCommerce cart update quantity field’ is closed to new replies.
