2

I am trying to get product attribute slug. I have used below code but it display name.

echo $_product->get_attribute( 'pa_color' );

I am working on woocommerce/cart/cart.php file in theme folder.

Also I checked this is coming in anchor url of product image in cart page but not getting it

anchor url: https://example.com/productos/sweatshirt/?attribute_pa_color=aa2757&attribute_pa_talla=m

I am working on this from today morning but I have not get success. Please guide.

enter image description here

2
$att=$_product->get_attribute('pa_color');

$values = wc_get_product_terms( $product->id, 'pa_color', array( 'fields' => 'all' ) );
foreach($values as $val){
  echo "<pre>";
  var_dump($val->slug);
  echo "</pre>";
}
  • I used this code, its showing all attributes but i need only one respective attribute. – Abi Sharma Jul 14 '18 at 16:02
  • @AbiSharma - I just found something related to what you are searching for in below question....just display variable value using below thread implementation. wordpress.stackexchange.com/questions/240283/… – dhirenpatel22 Jul 14 '18 at 18:30
2

I got this....

To get slug use:

$attributes = $_product->get_attributes();
$pa_color = $attributes["pa_color"];

Thanks to all for helping me.

0

Use next:

$attribute->get_name()
  • 1
    Could you elaborate a bit why this is a solution? You should post answers here and not only solutions :) – Krzysiek Dróżdż Mar 12 at 8:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.