복붙노트

[WORDPRESS] 하나 이상의 활성 변화에 대한 사용자 정의 Woocommerce 변수 제품 가격 범위

WORDPRESS

하나 이상의 활성 변화에 대한 사용자 정의 Woocommerce 변수 제품 가격 범위

해결법


  1. 1.당신의 첫번째 기능에 가시의 아이를 계산하면 그것을 달성 할 수 있습니다. 또한 나는 이름을 지정해야합니다 당신의 제 2 기능을 재 방문했다 :

    당신의 첫번째 기능에 가시의 아이를 계산하면 그것을 달성 할 수 있습니다. 또한 나는 이름을 지정해야합니다 당신의 제 2 기능을 재 방문했다 :

    add_filter( 'woocommerce_variable_price_html', 'custom_variation_price_html', 20, 2 );
    function custom_variation_price_html( $price_html, $product ) {
        $visible_children = $product->get_visible_children();
        if( count($visible_children) <= 1 ) return $price_html; // Exit if only one variation
    
        $regular_price_min = $product->get_variation_regular_price( 'min', true );
        $sale_price_min = $product->get_variation_sale_price( 'min', true );
    
        if ( $sale_price_min ) 
            $price_html = __( 'From', 'woocommerce' ).' '.wc_price( $regular_price_min );
    
        return $price_html;
    }
    
    add_filter('woocommerce_available_variation', 'custom_available_variation', 20, 3 ) ;
    function custom_available_variation( $args, $product, $variation ) {
        if( $args['price_html'] == '' )
            $args['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
        
        return $args;
    }
    

    이 코드는 활성 자식 테마 (또는 테마)의 function.php 파일에 간다.

    테스트 및 작동합니다.

  2. from https://stackoverflow.com/questions/48832078/custom-woocommerce-variable-product-price-range-for-more-than-one-active-variati by cc-by-sa and MIT license