Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created March 19, 2017 23:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save damiencarbery/52c1a8c9a9b891cd38ae7bc34b6c5452 to your computer and use it in GitHub Desktop.
Save damiencarbery/52c1a8c9a9b891cd38ae7bc34b6c5452 to your computer and use it in GitHub Desktop.
WooCommerce Single Page Layout - change it with just add_action()
<?php
/*
Plugin Name: Change Single Product Layout
Plugin URI: http://www.damiencarbery.com
Description: Change layout of Single Product page by changing add_action() order.
Author: Damien Carbery
Version: 0.1
*/
add_action( 'woocommerce_before_single_product', 'cspl_change_single_product_layout' );
function cspl_change_single_product_layout() {
// Disable the hooks so that their order can be changed.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
// Put the price first.
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 5 );
// Include the category/tags info.
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 10 );
// Then the product short description.
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 40 );
// Move the title to near the end.
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 50 );
// And finally include the 'Add to cart' section.
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 60 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment