问题
In single product pages, I would like to change the location of "additional information" from tabs, under add to cart button using Woocommerce hooks (removing the "additional information" tab).
I have:
add_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
and: woocommerce_after_add_to_cart_button
I'm trying:
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_after_add_to_cart_button', 'woocommerce_product_additional_information' );
and
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_product_additional_information', 60 );
But it doesn't work.
How can I move properly "additional information" below add to cart button?
回答1:
The following code will remove additional information tab and add additional information below add to cart:
// Remove additional information tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 100, 1 );
function remove_additional_information_tab( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// Add "additional information" after add to cart
add_action( 'woocommerce_single_product_summary', 'additional_info_under_add_to_cart', 35 );
function additional_info_under_add_to_cart() {
global $product;
if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
wc_display_product_attributes( $product );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
来源:https://stackoverflow.com/questions/52263008/move-additional-information-from-product-tab-under-add-to-cart-button-in-woocomm