Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing attributes to short description on single product page #53

Open
co-key opened this issue Feb 16, 2018 · 0 comments
Open

Showing attributes to short description on single product page #53

co-key opened this issue Feb 16, 2018 · 0 comments

Comments

@co-key
Copy link

co-key commented Feb 16, 2018

HI,

I'm trying to get the product attributes to be shown on the short description on the single productpage. I have found a code on this site, that is doing the trick. The only problem is that it if I use the shortcode in the description of the product, you don't see the language tags "[:en]tekst[:]" but if I add the function to 'woocommerce_single_product_summary', it does show me the language tags.

So my question is where does it goes wrong?

This is the code that I have been using (with thanks to: Rachel McCollin):
`
/**

  • Displays product attributes in the top right of the single product page.

  • @param $product
    */
    function tutsplus_list_attributes( $product ) {

    global $product;
    global $post;

$attributes = $product->get_attributes();

if ( ! $attributes ) {

return;

}

foreach ( $attributes as $attribute ) {

// Get the taxonomy.
$terms = wp_get_post_terms( $product->id, $attribute[ 'name' ], 'all' );
$taxonomy = $terms[ 0 ]->taxonomy;
      
// Get the taxonomy object.
$taxonomy_object = get_taxonomy( $taxonomy );
 
// Get the attribute label.
$attribute_label = $taxonomy_object->labels->name;
 
// Display the label followed by a clickable list of terms.
echo get_the_term_list( $post->ID, $attribute[ 'name' ] , '<div class="attributes">' . $attribute_label . ': ' , ', ', '</div>' );

}

}
add_shortcode( 'display_attributes', 'tutsplus_list_attributes' );
add_action( 'woocommerce_single_product_summary', 'tutsplus_list_attributes' );
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant