Move the Cart in a WooCommerce Single Product

/Move the Cart in a WooCommerce Single Product

WooCommerce is a fantastic WordPress plugin, but unless you’re really familiar with how it works you may run into a number of things that, on the surface at least, can not be done. One such thing is modifying the single product page template to rearrange the elements.

To do this you need to understand the woocommerce_single_product_summary action that you can find in content-single-product.php. Upon closer inspection, you’ll see something instantly familiar about the programming below. It’s actually the order of your single product layout.

         * woocommerce_single_product_summary hook
         * @hooked woocommerce_template_single_title - 5
         * @hooked woocommerce_template_single_price - 10
         * @hooked woocommerce_template_single_excerpt - 20
         * @hooked woocommerce_template_single_add_to_cart - 30
         * @hooked woocommerce_template_single_meta - 40
         * @hooked woocommerce_template_single_sharing - 50
        do_action( 'woocommerce_single_product_summary' );

Modifying the order isn’t that difficult either, and the most common way of doing this is to add a few lines to your theme’s functions.php. Try this on for size:

/** Change Add to Cart Position in WooCommerce **/
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 9 );

All we’re really doing is firstly removing the default action from the top code we looked at earlier, and replacing it with a new order. The “30” and “9” are the order in which the item displays in the grand scheme of things. Simple really, isn’t it?

2018-02-02T03:09:31+00:00January 25th, 2015|Programming Tips, Web Programming|0 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.