4

How to move the product meta to the beginning of the product description tab? I try:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_product_tabs_description', 'woocommerce_template_single_meta', 10 );

Remove works, but add_action() doesn't.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Pat
  • 697
  • 3
  • 11
  • 30

2 Answers2

1

You can keep the first code line. Then to insert single product meta on product description tab, before description, you can use 2 different ways:

1). Using Hooks as follows:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

add_filter( 'woocommerce_product_tabs', 'woocommerce_custom_product_tabs', 999 );
function woocommerce_custom_product_tabs( $tabs ) {
    // We overwrite the callback function with a custom one
    $tabs['description']['callback'] = 'woocommerce_product_meta_and_description_tab';

    // (optional) We can also overwrite the title
    $tabs['description']['title'] = __('Meta and description', 'woocommerce');

    return $tabs;
}

function woocommerce_product_meta_and_description_tab() { // this is where you indicate what appears in the description tab
    wc_get_template( 'single-product/meta.php' ); // The meta content first
    wc_get_template( 'single-product/tabs/description.php' ); // The product description after
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.


2). Or Overriding templates:

You can override single-product/tabs/description.php template file via your theme as explained in this official documentation.

Once you have copied the file to the woocommerce folder inside your active theme, open edit single-product/tabs/description.php file and add the following line inside it:

wc_get_template( 'single-product/meta.php' );

It will displays the product meta information inside the product description tab.

Don't forget to keep in your active child theme's functions.php file:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

Related: WooCommerce action hooks and overriding templates

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
-1

There actually is a way to do this within your functions without copying files from woocommerce and overriding them in your child theme.

Per WooCommerce documentation, you can customize the product data tabs. With a small modification to the code they provided, you can do what you're asking:

/**
 * Customize product data tabs
 */
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {

    $tabs['description']['callback'] = 'woo_custom_description_tab_content';    // Custom description callback

    return $tabs;
}

function woo_custom_description_tab_content() { // this is where you indicate what appears in the description tab
    wc_get_template( 'single-product/meta.php' ); // add this to add meta to content
    the_content(); // keep this in to preserve original functionality
}
aronmoshe_m
  • 908
  • 1
  • 6
  • 15