how to get woocommerce product attribute slug

I am trying to get product attribute slug. I have used below code but it display name. echo $_product->get_attribute(

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: /?attribute_pa_color=aa2757&attribute_pa_talla=m

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

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/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.

Share Improve this question edited Jul 14, 2018 at 15:55 Abhilesh Sharma asked Jul 14, 2018 at 15:24 Abhilesh SharmaAbhilesh Sharma 1571 gold badge1 silver badge8 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 8

I got this....

To get slug use:

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

Thanks to all for helping me.

$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>";
}

To get attribute slug by attribute id:

$attribute_id = 3;
$attribute = wc_get_attribute($attribute_id);
echo $attribute->slug // example it will return pa_color

Use next:

$attribute->get_name()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744348848a4569855.html

相关推荐

  • how to get woocommerce product attribute slug

    I am trying to get product attribute slug. I have used below code but it display name. echo $_product->get_attribute(

    7天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信