2021年3月2日星期二

Is it possible to show an specific product attribute in Elementor product page?

I'm trying to add a specific product attribute ( in this case, the "warranty" ) to the elementor custom product page. I have tried using "PHP Code Snippets" plugin and adding:

<?php  add_action( 'woocommerce_single_product_summary', 'product_attribute_after_price', 15 );  function product_attribute_after_price () {      global $product;        // HERE add your product attribute SLUG or taxonomy      $attribute_slug = 'guarantee';        $taxonomy = strpos($url, 'blog') !== false ? $attribute_slug : 'pa_' . $attribute_slug;      $attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;      $term_name = $product->get_attribute( $taxonomy ); // The value        if( empty($term_name) ) return; // Exit if empty value        // If not empty we display it      $output  = '<div class="product-attribute '.$taxonomy.'"><p>';      $output .= '<strong> '.$attribute_name.'</strong>: ';      $output .= '<span> '.$term_name.'</span>';      echo $output . '</p></div>';  }  

but that shows nothing.

what should i do?

https://stackoverflow.com/questions/66451077/is-it-possible-to-show-an-specific-product-attribute-in-elementor-product-page March 03, 2021 at 01:04PM

没有评论:

发表评论