簡單的問題如何在購物車woocomerce中顯示產品屬性:例如顏色:紅色,不確定是否有一些代碼需要像hook或代碼一樣添加到fundctions.php,或者它可以是通過woocomerce設置完成,沒有在網上找到任何有用的信息,任何幫助表示讚賞。在購物車中顯示屬性值和名稱woocomerce
0
A
回答
2
剛做一件簡單的事情如下,你會得到你所有的cart_item -
add_filter('woocommerce_cart_item_name', 'add_variations_in_cart', 10, 3);
function add_variations_in_cart($name, $cart_item, $item_key){
$product_variation = '';
if(!empty($cart_item['variation_id']) && $cart_item['variation_id'] != 0){
if(is_array($cart_item['variation']) && !empty($cart_item['variation'])){
foreach ($cart_item['variation'] as $key => $value) {
$product_variation .= '<br>'.ucfirst(str_replace('attribute_pa_', '', $key)).' : '.ucfirst($value);
}
}
}
echo $name.$product_variation;
}
就這麼簡單。謝謝。
0
酪氨酸這個插件https://wordpress.org/plugins/woocommerce-show-attributes/
OR
WooCommerce:我的購物車頁面上的每個項目下面列出的所有產品屬性
在function.php添加此下面的代碼
/**
* WooCommerce: show all product attributes listed below each item on Cart page
*/
function sm_woo_cart_attributes($cart_item, $cart_item_key){
$item_data = $cart_item_key['data'];
$attributes = $item_data->get_attributes();
if (! $attributes) {
return $cart_item;
}
$out = $cart_item . '<br />';
foreach ($attributes as $attribute) {
if ($attribute['is_taxonomy']) {
// skip variations
if ($attribute['is_variation']) {
continue;
}
// backwards compatibility for attributes which are registered as taxonomies
$product_id = $item_data->id;
$terms = wp_get_post_terms($product_id, $attribute['name'], 'all');
// get the taxonomy
$tax = $terms[0]->taxonomy;
// get the tax object
$tax_object = get_taxonomy($tax);
// get tax label
if (isset ($tax_object->labels->name)) {
$tax_label = $tax_object->labels->name;
} elseif (isset($tax_object->label)) {
$tax_label = $tax_object->label;
}
foreach ($terms as $term) {
$out .= $tax_label . ': ';
$out .= $term->name . '<br />';
}
} else {
// not a taxonomy
$out .= $attribute['name'] . ': ';
$out .= $attribute['value'] . '<br />';
}
}
echo $out;
}
add_filter('woocommerce_cart_item_name', sm_woo_cart_attributes, 10, 2);
+0
不工作,woocomerce 3.0版 – Zygimantas
+0
試試這個插件https://wordpress.org/plugins/woocommerce-show-attributes/ –
相關問題
- 1. 購物車 - multple屬性值
- 2. 如何在購物車中顯示屬性的值?
- 3. Shopify購物車中的動態屬性名稱
- 4. Magento - 在購物車中顯示自定義屬性
- 5. Magento產品屬性沒有在結賬中顯示,在購物車中顯示
- 6. Intellij - 顯示和屬性值和名稱
- 7. 在購物車頁面顯示類別名稱
- 8. SimpleCart JS購物車顯示
- 9. 在表中顯示購物車
- 10. 購物車中的產品屬性opencart
- 11. Woocommerce購物車顯示重複購物車總計
- 12. Magento:添加到購物車顯示空的購物車
- 13. codeigniter購物車:多個商店的顯示購物車
- 14. 在購物車中添加產品簡要說明Woocomerce
- 15. 屬性附加值購物車結賬和訂單頁
- 16. 購物車中顯示總金額
- 17. Magento在購物車上顯示tierprice
- 18. Woocommerce購物車提示多次顯示
- 19. 添加屬性到購物車
- 20. 購物車上的屬性 - Magento
- 21. Shopify查詢購物車屬性
- 22. 購物車多屬性產品
- 23. AJAX - 購物車Magento總計和購物車中的物品
- 24. Magento如何在我的購物車鏈接上顯示購物車上的購物車信息
- 25. WooComerce:如何更改購物車中的標題文本
- 26. 在購物車中顯示Magento自定義選項值
- 27. 購物車會話和顯示購物車中的物品數量返回undefined在Laravel
- 28. 添加到購物車顯示「您的購物車中沒有產品」?
- 29. 如何在「購物車」標籤上顯示添加到購物車的數量
- 30. Magento:獲取購物車中的屬性值
如何增加自定義樣式的跨度?謝謝 – Zygimantas
你可以根據你的需要在$ product_variation中傳遞你的html結構。根據你的情況,像$ product_variation。='
'。ucfirst(str_replace('attribute_pa_','',$ key))。' :'.ucfirst($ value)。''; – itzmekhokan