Home / Admin / Add Custom Taxonomy to Woocommerce Single Product Page
Duplicate Snippet

Embed Snippet on Your Site

Add Custom Taxonomy to Woocommerce Single Product Page

Code Preview
php
<?php
add_action( 'woocommerce_product_meta_end', 'wcv_add_brands_single_product' );
function wcv_add_brands_single_product() {
    global $product;
    $taxonomy = 'wcv_brands'; // The custom taxonomy as defined during our register_taxonomy code above.
    if( ! taxonomy_exists( $taxonomy ) ){ 
        return; // exit
    }
        
    $term_ids = wp_get_post_terms( $product->get_id(), $taxonomy, array('fields' => 'ids') );
    if ( ! empty($term_ids) ) {
        echo get_the_term_list( $product->get_id(), 'wcv_brands', '<span class="posted_in">' . _n( 'Brand:', 'Brands:', count( $term_ids ), 'wc-vendors' ) . ' ', ', ', '</span>' );
    }
}

Comments

Add a Comment