Starting snippets for WooCommerce custom theme
Here is a list of snippets that I use when starting a new WooCommerce website; all these snippets must be pasted in the functions.php
file within your theme folder:
Add Theme Support for WooCommerce
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
Remove default WooCommerce stylesheets
add_filter( 'woocommerce_enqueue_styles', 'yabu_dequeue_styles' );
function yabu_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
Remove default WooCommerce wrapper
I usually want to remove the default wrapping container and replace it with a more appropriate tag that matches the rest of my site.
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'yabu_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'yabu_theme_wrapper_end', 10);
function yabu_theme_wrapper_start() {
echo '<div class="woo-container">';
}
function yabu_theme_wrapper_end() {
echo '</div> ';
}
Change “Add to cart” button text
add_filter('woocommerce_product_single_add_to_cart_text', 'yabu_custom_cart_button_text');
function yabu_custom_cart_button_text() {
return __('My button text', 'woocommerce');
}
Remove product tabs
Usually, I don’t need product tabs.
add_filter( 'woocommerce_product_tabs', 'yabu_remove_product_tabs', 98 ); function yabu_remove_product_tabs( $tabs ) { unset( $tabs['description'] ); // Remove the description tab unset( $tabs['reviews'] ); // Remove the reviews tab unset( $tabs['additional_information'] ); // Remove the additional information tab return $tabs; }