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 badges4 Answers
Reset to default 8I 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
评论列表(0条)