WooCommerce, Remote Work & Other Fancy Stuff

Just another WordPress site

Move WooCommerce Box Office Form Fields

May 31, 2016 by Will 9 Comments

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?

Filed Under: Box Office Tagged With: snippet

Comments

  1. kelleynunn says

    April 10, 2017 at 2:45 pm

    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.

    Log in to Reply
    • will says

      April 10, 2017 at 8:51 pm

      snippet updated

      Log in to Reply
      • kelleynunn says

        April 10, 2017 at 8:54 pm

        Beautiful. Thank you!

        Log in to Reply
  2. jalalcharafifeat says

    April 30, 2017 at 7:26 pm

    Hi there,

    I still did not update WooCommerce and would love to have the previous version of the snippet to use it please!

    Thanks

    Log in to Reply
    • will says

      April 30, 2017 at 7:32 pm

      See https://gist.github.com/WillBrubaker/609aa54fb50b06d5ebba12ad5986152e/f2b04c5e1658473634df9a3582d418df2337ff4b

      Log in to Reply
      • will says

        April 30, 2017 at 7:34 pm

        To clarify that, see the “revisions” tab for the full history.

        Log in to Reply
  3. jalalcharafifeat says

    May 6, 2017 at 4:12 pm

    Thank you Will!

    Is there a way to move only the button and leave the quantity field before the tickets fields?

    Jalal

    Log in to Reply
    • will says

      May 12, 2017 at 12:37 pm

      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.

      Log in to Reply
      • james@smoothdevelopments.com.au says

        March 29, 2018 at 6:01 am

        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 );
        }
        }

        Log in to Reply

Leave a Reply Cancel reply

You must be registered and logged in to post a comment.

© 2023 ยท WooCommerce, Remote Work & Other Fancy Stuff · Epstein didn't kill himself