I'm trying to create a WooCommerce bookshop for a client, and need to create a custom taxonomy for the books' authors. I've managed to get the taxonomy working in wp-admin by inserting the following code into functions.php:

add_action( 'init', 'authors' );
function authors()  {
$labels = array(
    'name'                       => 'Authors',
    'singular_name'              => 'Author',
    'menu_name'                  => 'Authors',
    'all_items'                  => 'All Authors',
    'parent_item'                => 'Parent Author',
    'parent_item_colon'          => 'Parent Author:',
    'new_item_name'              => 'New Author Name',
    'add_new_item'               => 'Add New Author',
    'edit_item'                  => 'Edit Author',
    'update_item'                => 'Update Author',
    'separate_items_with_commas' => 'Separate Authors with commas',
    'search_items'               => 'Search Authors',
    'add_or_remove_items'        => 'Add or remove Authors',
    'choose_from_most_used'      => 'Choose from the most used Authors',
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
register_taxonomy( 'item', 'product', $args );
register_taxonomy_for_object_type( 'item', 'product' );

But I can't seem to pull any of this through to the product page, where I want to display the author's name. I've been trying to use the <?php echo get_the_terms( $name, $authors ); ?> hooked to woocommerce_single_product_summary in an attempt to get at least some data to display, but debug keeps throwing up Undefined variable errors.

Chances are, I'm missing something rather basic, but all the same, I'd really appreciate some help.

Thanks, Josh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.