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产品页面删除不需要的JavaScript产品页面
- 5. (Shopify)如何显示产品页面上的库存水平?
- 6. 如何删除WordPress的Woocommerce从产品分类页面价格
- 7. Woocommerce - 在订单页面中显示产品摘录页面
- 8. WooCommerce - 获取产品页面的类别
- 9. Woocommerce产品的变化:的“库存”
- 10. Woocommerce产品分类描述的产品页面
- 11. WooCommerce - 确定当前单个产品页面的产品类别
- 12. 限制产品类别为'x'的产品页面WooCommerce
- 13. wordpress woocommerce单一产品页面定制
- 14. Woocommerce产品页面布局不正确
- 15. 操作woocommerce产品编辑页面
- 16. CSS风格Woocommerce单产品页面
- 17. 需要显示产品页面中的当前产品属性woocommerce
- 18. 显示woocommerce相关产品下的产品图库
- 19. WooCommerce产品 - 显示产品对象
- 20. 使用FlexSlider显示WooCommerce产品库
- 21. WooCommerce;从商店页面和单品页面删除产品图像
- 22. 如何显示woocommerce组产品中的儿童产品图像?
- 23. 从WooCommerce的特定产品页中删除产品缩略图
- 24. 向同一页面显示类似的变体产品 - WooCommerce
- 25. 如何显示WooCommerce产品未销售?
- 26. Woocommerce:如何删除结帐页面上的产品线?
- 27. 从woocommerce网站获取woocommerce数据库中的销售产品和库存
- 28. 产品页面上的Woocommerce类别特定代码页面
- 29. 返回从woocommerce过滤产品列表
- 30. 如何在产品评论页面显示产品长描述?
检查这个https://gist.github.com/mujuonly/7c1393f791fdeb261c0225a32cec574e –
@MujeebuRahman YOU ARE生命的救星!!!! OMG <3我正在寻找这个解决方案3周!谢谢!谢谢!谢谢!谢谢! –