I'd like to display the custom attribute book_author
below the product title on single product pages, like so:
Product title
book_author
Price
I've come across various solutions for achieving similar changes to woocommerce_single_product_summary
but none that has successfully displayed a linked custom attribute between the title and price.
I've achieved the desired result on the shop loop using the following, so if there was a way to adapt this code to apply to single product pages also, that would be ideal.
add_action( 'woocommerce_after_shop_loop_item_title', 'display_book_author_attribute', 5 );
function display_book_author_attribute() {
global $product;
if ( $product->is_type('simple') ) {
$taxonomy = 'pa_book_author';
echo '<span class="attribute-book_author">' . $product->get_attribute($taxonomy) . '</span>';
}
}
Any and all advice would be hugely appreciated here, thanks so much!
Edit: I can use both action hooks together for the same function, however (to my knowledge) this then ties <span class>
meaning I'm unable to style the attribute differently on shop pages and product pages, ie:
```add_action( 'woocommerce_single_product_summary', 'display_book_author_attribute', 5 );
add_action( 'woocommerce_after_shop_loop_item_title', 'display_book_author_attribute', 5 );
function display_book_author_attribute() {
global $product;
if ( $product->is_type('simple') ) {
$taxonomy = 'pa_book_author';
echo '<span class="attribute-book_author">' . $product->get_attribute($taxonomy) . '</span>';
}
}`