WooCommerce

WooCommerce Useful Snippets

Updated at

Continuing my journey of developing my newest smartphone community and comparison website, BestGadgetForum.com, I list useful snippets for WooCommerce customizations. In some areas I want elements to be removed, or modified so it can fit the look I’ve dreamt of. Check it out below!

Remove WooCommerce Breadcrumbs

I’m gonna use a more SEO friendly breadcrumb that uses Schema markup, so the default WooCommerce breadcrumb located on the product page needs to be removed.

/**
 * Remove the breadcrumbs 
 */
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}

Remove Category (Product Meta) on WooCommerce Product Page

add_action( 'after_setup_theme', function() {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
} );

Remove Short Description on WooCommerce Product Page

add_action( 'after_setup_theme', function() {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
} );

Remove Product Price on WooCommerce Product Page

add_action( 'after_setup_theme', function() {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
} );

Disable Shopping Functions / Remove Add to Cart Button

This filter below works for simple product. I’ve tried to use it on external/affiliate product, but the Buy Button is still there. So the best practice is to use simple product in your product type.

add_filter( 'woocommerce_is_purchasable', '__return_false');

Or use this one if you want to remove Add to Cart/Read More button on product archive page

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); //Remove Add to Cart/Read More Button on Product Archive Page
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 ); //Remove Single Product Image

Remove Single Page Product Tabs: Description, Additional Information, Reviews

add_filter( 'woocommerce_product_tabs', 'diko_remove_product_tabs', 81 );
function diko_remove_product_tabs( $tabs ) {
    unset( $tabs['description'] );
	unset( $tabs['additional_information']);
	unset( $tabs['reviews']);
    return $tabs;
}
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

Remove WooCommerce Title

add_filter( 'woocommerce_show_page_title', 'diko_remove_woo_title');
function diko_remove_woo_title(){
    if(is_shop()){
        return false;
    }
}

Sources

  1. https://woocommerce.com/document/customise-the-woocommerce-breadcrumb/
  2. https://wpbeaches.com/removing-the-product-meta-categories-in-a-product-page-woocommerce/
  3. https://rudrastyh.com/woocommerce/make-products-non-purchasable.html