如何解决从 WooCommerce 购物车中获取变体属性标签名称和价值产品
我应该获取购物车中产品的所有数据(产品名称和单个产品的属性)。作为参考,我有这段代码允许每个产品只显示一个属性。
您能帮我找到查看所有属性的解决方案吗? 商店里一共有10个属性
$taxonomy = 'pa_selezione-pezzi';
// Get an instance of the WC_Product Object (necessary if you don't have it)
// from a dynamic $product_id (or defined $product_id)
$product = wc_get_product($product_id);
// Iterating through the product attributes
foreach($product->get_attributes() as $attribute){
// Targeting the defined attribute
if( $attribute->get_name() == $taxonomy ){
// Iterating through term IDs for this attribute (set for this product)
foreach($attribute->get_options() as $term_id){
// Get the term slug
$term_slug = get_term( $term_id,$taxonomy )->slug;
// Output
$confirmation = str_ireplace("{term_slug}",$term_slug,$confirmation);
}
}
}
解决方法
如果您要检索产品变体购物车项目中设置的产品属性,可以使用以下代码示例:
for (let i = 0; i < array2.length; i++) {
if (!array1.includes(array2[i])) {
array1.push(array2[i])
}
}
经过测试并有效
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。