如何回应库存;从WooCommerce的产品页面?

如何回应库存;从WooCommerce的产品页面?,woocommerce,echo,stock,variation,Woocommerce,Echo,Stock,Variation,我试图在产品页面内再次打印“库存”,但我找不到解决方案,我如何才能回显它。默认情况下,在图像上显示,但我想在同一页上再次显示,如何回显/打印该图像 谢谢 >>>1个库存图像函数wc\u下拉列表\u变量\u属性\u选项($args=array()){ 全球$产品; $variations=$product->get_available_variations(); $args=wp\u parse\u args(应用过滤器('woocommerce\u dropdown\u variation\u

我试图在产品页面内再次打印“库存”,但我找不到解决方案,我如何才能回显它。默认情况下,在图像上显示,但我想在同一页上再次显示,如何回显/打印该图像

谢谢

>>>1个库存图像
函数wc\u下拉列表\u变量\u属性\u选项($args=array()){
全球$产品;
$variations=$product->get_available_variations();
$args=wp\u parse\u args(应用过滤器('woocommerce\u dropdown\u variation\u attribute\u options\u args',$args),数组(
“选项”=>false,
'attribute'=>false,
“产品”=>错误,
'所选'=>false,
'名称'=>'',
“id'=>”,
“类”=>“”,
'show_option_none'=>uuu('Choose an option','woocommerce'),
) );
$options=$args['options'];
$product=$args['product'];
$attribute=$args['attribute'];
$name=$args['name']?$args['name']:'attribute'。清理标题($attribute);
$id=$args['id']?$args['id']:清理标题($attribute);
$class=$args['class'];
if(空($options)&!空($product)&&!空($attribute)){
$attributes=$product->get_variation_attributes();
$options=$attributes[$attribute];
}
$html='';
如果($args['show\u option\u none'])){
$html.=''.esc_html($args['show_option_none']);
}
如果(!空($options)){
/*如果($product&&TAXINOMATY_存在($attribute)){
//如果这是按分类法排序的,则获取术语。我们也需要名称。
$terms=wc_get_product_terms($product->get_id(),$attribute,数组('fields'=>'all'));
foreach($terms作为$term){
if(在数组中($term->slug$options)){
$html.=''.esc_html(应用过滤器('woocommerce_variation_option_name',$term->name))。';
}
}
}否则{*/
foreach($options作为$option){
foreach($变更为$变更){
如果($variation['attributes'][$name]==$option){
$stock=esc_html($variation['max_qty']);
}
}
如果($stock==0){
$stock_text='—(缺货)';
$class='期权缺货';
$disabled='disabled';
}elseif(库存<5美元){
$stock_text='-仅限'$stock.'左!';
$class='optionharse';
$disabled='';
}elseif(库存<6美元){
$stock_text='-只剩下几个了!';
$class='optionnow';
$disabled='';
}否则{
$stock_text='—(库存中)';
$class='';
$disabled='';
}
//这将处理<2.4.0 bw兼容性,其中未对文本属性进行清理。
$selected=清理标题($args['selected'])==$args['selected']?selected($args['selected'],清理标题($option),false):selected($args['selected'],$option,false);
$html.=''.$option.$stock_text.';
//}
}
}
$html.='';
echo应用过滤器('woocommerce_下拉列表_变体_属性_选项_html',$html,$args);
}

检查这个@MujeebuRahman你是个救生员!!!!对象管理组织
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 );
    }