programing

WooCommerce 무료배송 라벨 맞춤 기능

subpage 2023. 10. 26. 21:03
반응형

WooCommerce 무료배송 라벨 맞춤 기능

다음과 같은 사항을 제 기능에 반영할 때.php 그것은 내 사이트 전체를 크래시합니다.이 기능의 목적은 변화하는 것입니다.

elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( '**Free**', 'woocommerce' ) . ')';

여기에...

elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( '**To Be Calculated**', 'woocommerce' ) . ')';

원래 wocommerce/include/wc-cart-functions에서 한 단어를 변경할 때.php 그것은 완벽하게 작동합니다.업데이트로 덮어쓰기를 원하지 않습니다.

/**
* Get a shipping methods full label including price
* @param  object $method
* @return string
*/
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->label;

if ( $method->cost > 0 ) {
    if ( WC()->cart->tax_display_cart == 'excl' ) {
        $label .= ': ' . wc_price( $method->cost );
        if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
            $label .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
        }
    } else {
        $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
        if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
            $label .= ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>';
        }
    }
} elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( 'To Be Calculated', 'woocommerce' ) . ')';
}

return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}

만약 당신이 최신 woo commerce를 사용한다면 필터를 따르는 것이 당신에게 도움이 될 것입니다.

add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_local_pickup_free_label', 10, 2 );
function remove_local_pickup_free_label($full_label, $method){
    $full_label = str_replace("(Free)","(TBD)",$full_label);
return $full_label;
}

필터를 통해 기능을 재구축해야 합니다.교체할 때 각 언어를 선택하지 않는 한 str_replace를 사용하면 번역된 설치에서는 작동하지 않습니다.

function ua_woocommerce_cart_shipping_method_full_label( $label, $method ) {
$label = $method->label;

if ( $method->cost > 0 ) {
    if ( WC()->cart->tax_display_cart == 'excl' ) {
        $label .= ': ' . wc_price( $method->cost );
        if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
            $label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
        }
    } else {
        $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
        if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
            $label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
        }
    }
} 

return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'ua_woocommerce_cart_shipping_method_full_label', 10, 2 );

언급URL : https://stackoverflow.com/questions/22353854/woocommerce-custom-function-for-free-shipping-label

반응형