Display product attribute archive links
-
Hi there, I’m using WP page bakery and I’d like to display an archive product attribute on the page (a page with the products’ brand name).
Here’s what I achieved so far, but is not working:
function wpc_vc_shortcode( $atts ) { global $post; $attribute_names = array( 'pa_brand'); // Add attribute names here and remember to add the pa_ prefix to the attribute name foreach ( $attribute_names as $attribute_name ) { $taxonomy = get_taxonomy( $attribute_name ); if ( $taxonomy && ! is_wp_error( $taxonomy ) ) { $terms = wp_get_post_terms( $post->ID, $attribute_name ); $terms_array = array(); if ( ! empty( $terms ) ) { foreach ( $terms as $term ) { $archive_link = get_term_link( $term->slug, $attribute_name ); $full_line = '<a href="' . $archive_link . '">'. $term->name . '</a>'; array_push( $terms_array, $full_line ); } echo $taxonomy->labels->name . ' ' . implode( $terms_array, ', ' ); } } } } add_shortcode( 'my_vc_php_output', 'wpc_vc_shortcode');Basically is what is achieved by this plugin:
https://wordpress.org/plugins/wcpas-product-attributes-shortcode/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Display product attribute archive links’ is closed to new replies.