Please consider leaving a donation if you appreciate this information. Lightning network now available
By Default, WooCommerce Box Office renders the add to cart/buy ticket now button before the form fields. In some cases this may be undesirable. If you would rather render the fields before the button, use the below snippet of code:
Not sure what to do with code snippets? See What Do I Do With These Code Snippets?
Please consider leaving a donation if you appreciate this information. Lightning network now available
Hey! Thank you for this code snippet — it worked perfectly! Unfortunately, since the WooCommerce 3.0 update, the snippet no longer works and returns a php error. What changes can we make to the snippet to get it back in working order?
Thanks for your help! Much appreciated.
snippet updated
Beautiful. Thank you!
Hi there,
I still did not update WooCommerce and would love to have the previous version of the snippet to use it please!
Thanks
See https://gist.github.com/WillBrubaker/609aa54fb50b06d5ebba12ad5986152e/f2b04c5e1658473634df9a3582d418df2337ff4b
To clarify that, see the “revisions” tab for the full history.
Thank you Will!
Is there a way to move only the button and leave the quantity field before the tickets fields?
Jalal
For simple products, the qty field is output here: https://github.com/woocommerce/woocommerce/blob/3.0.6/templates/single-product/add-to-cart/simple.php#L46-L50 , for variable products, it’s output via an action hook here: https://github.com/woocommerce/woocommerce/blob/3.0.6/templates/single-product/add-to-cart/variable.php#L64-L66 so yes, there’s a way, it’s a matter of figuring out how to handle different situations.
Here’s the adjusted code as tested on WooCommerce 3.34 + Box Office 1.16
This code will move the form fields AFTER the quantity box.
NOTE: Add to your functions.php file in your CHILD THEME.
// Remove the related products from WooCommerce single product screen
remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );
add_action( ‘woocommerce_init’, ‘handsome_bearded_guy_move_box_office_cartbutton’ );
function handsome_bearded_guy_move_box_office_cartbutton() {
//ensure the function exists before trying to accecss it – avoids WSOD
if ( function_exists( ‘WCBO’ ) )
{
if ( method_exists( ‘WC_Box_Office’, ‘init’ ) )
{
WCBO()->init();
}
// remove the action
remove_action( ‘woocommerce_after_add_to_cart_button’, array( WCBO()->components->cart, ‘render_ticket_fields’ ), 20 );
// add it back so that the add to cart button comes after the form fields
add_action( ‘woocommerce_after_add_to_cart_quantity’, array( WCBO()->components->cart, ‘render_ticket_fields’ ), 20 );
}
}