0
A
回答
0
function wc_dropdown_variation_attribute_options($args = array()) {
global $product;
$variations = $product->get_available_variations();
$args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array(
'options' => false,
'attribute' => false,
'product' => false,
'selected' => false,
'name' => '',
'id' => '',
'class' => '',
'show_option_none' => __('Choose an option', 'woocommerce'),
));
$options = $args['options'];
$product = $args['product'];
$attribute = $args['attribute'];
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
$id = $args['id'] ? $args['id'] : sanitize_title($attribute);
$class = $args['class'];
if (empty($options) && ! empty($product) && ! empty($attribute)) {
$attributes = $product->get_variation_attributes();
$options = $attributes[ $attribute ];
}
$html = '<select id="' . esc_attr($id) . '" class="' . esc_attr($class) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">';
if ($args['show_option_none']) {
$html .= '<option value="">' . esc_html($args['show_option_none']) . '</option>';
}
if (! empty($options)) {
/*if ($product && taxonomy_exists($attribute)) {
// Get terms if this is a taxonomy - ordered. We need the names too.
$terms = wc_get_product_terms($product->get_id(), $attribute, array('fields' => 'all'));
foreach ($terms as $term) {
if (in_array($term->slug, $options)) {
$html .= '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $term->name)) . '</option>';
}
}
} else {*/
foreach ($options as $option) {
foreach ($variations as $variation) {
if($variation['attributes'][$name] == $option) {
$stock = esc_html($variation['max_qty']);
}
}
if($stock == 0) {
$stock_text = ' - (Out of Stock)';
$class = 'option-out-of-stock';
$disabled = 'disabled';
} elseif ($stock < 5) {
$stock_text = ' - Only ' . $stock . ' left!';
$class= 'option-hurry';
$disabled = '';
} elseif ($stock < 6) {
$stock_text = ' - Only a few left!';
$class = 'option-few';
$disabled = '';
} else {
$stock_text = ' - (In Stock)';
$class = '';
$disabled = '';
}
// This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
$selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false);
$html .= '<option value="' . esc_attr($option) . '" ' . $selected . ' class="'.$class.'" '.$disabled.'>' . $option . $stock_text .'</option>';
//}
}
}
$html .= '</select>';
echo apply_filters('woocommerce_dropdown_variation_attribute_options_html', $html, $args);
}
相關問題
- 1. Woocommerce產品頁面未顯示產品
- 2. woocommerce顯示特定頁面的產品
- 3. WooCommerce - 從產品頁面刪除頁腳
- 4. Woocommerce - 從商店頁面中刪除可用產品庫存號
- 5. 如何編輯woocommerce產品頁面?
- 6. Woocommerce產品頁面定製
- 7. Woocommerce - 產品描述頁面
- 8. Woocommerce可變產品頁面
- 9. 如何從Woocommerce的商店頁面中刪除產品/庫存盤點?
- 10. Woocommerce - 只顯示產品庫存
- 11. 如何分離woocommerce的庫存產品和缺貨產品
- 12. 在Woocommerce產品頁面顯示更多產品元信息
- 13. 如何顯示在WordPress woocommerce特定頁面上的產品呢?
- 14. 從WooCommerce產品頁面刪除不需要的JavaScript產品頁面
- 15. Woocommerce - 從產品類別頁面中刪除產品縮略圖
- 16. 如何在單個產品頁面上顯示woocommerce產品標籤。
- 17. (Shopify)如何顯示產品頁面上的庫存水平?
- 18. 如何刪除WordPress的Woocommerce從產品分類頁面價格
- 19. Woocommerce - 在訂單頁面中顯示產品摘錄頁面
- 20. 僅從產品詳細頁面隱藏jQuery庫Wordpress(WooCommerce)
- 21. Woocommerce - 獲得產品頁面的運費
- 22. WooCommerce - 獲取產品頁面的類別
- 23. WordPress的WooCommerce產品頁面模板
- 24. 刪除woocommerce產品頁面的列
- 25. Woocommerce產品的變化:的「庫存」
- 26. Woocommerce-重置產品頁面上的產品縮略圖大小
- 27. Woocommerce產品分類描述的產品頁面
- 28. WooCommerce - 確定當前單個產品頁面的產品類別
- 29. 限制產品類別爲'x'的產品頁面WooCommerce
- 30. WPML + Woocommerce產品404頁面錯誤
檢查這個https://gist.github.com/mujuonly/7c1393f791fdeb261c0225a32cec574e –
@MujeebuRahman YOU ARE生命的救星!!!! OMG <3我正在尋找這個解決方案3周!謝謝!謝謝!謝謝!謝謝! –