Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 8, 2021 17:40
Show Gist options
  • Select an option

  • Save jorpdesigns/4b5b892133dd15fa9ec691f5d6168b44 to your computer and use it in GitHub Desktop.

Select an option

Save jorpdesigns/4b5b892133dd15fa9ec691f5d6168b44 to your computer and use it in GitHub Desktop.
Snippet to remove default product tabs and add custom tabs on WooCommerce product page
<?php
add_filter( 'woocommerce_product_tabs', 'remove_product_tabs', 20 );
function 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;
}
/**
* ADDS CUSTOM PRODUCT TABS
*/
add_filter( 'woocommerce_product_tabs', 'custom_product_tabs' );
function custom_product_tabs( $tabs ) {
$tabs['custom_tab'] = array(
'title' => __( 'Custom Tab', 'woocommerce' ),
'priority' => 40,
'callback' => 'custom_tab_content'
);
// ONLY ADD TAB IF IT HAS VALUE IN BACKEND
if ( get_field('custom_tab') ) :
$tabs['custom_tab'] = array(
'title' => __( 'Custom Tab', 'woocommerce' ),
'priority' => 40,
'callback' => 'custom_tab_content'
);
endif;
return $tabs;
}
// The new tabs content
function custom_tab_content() {
echo get_field('custom_tab');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment