programing

WooCommerce 이메일 알림에서 로컬 픽업 시 발송 주소 숨기기

lastcode 2023. 9. 24. 12:55
반응형

WooCommerce 이메일 알림에서 로컬 픽업 시 발송 주소 숨기기

"로컬 픽업"을 선택한 경우 고객의 처리 이메일에 "배송 주소" 정보란을 어떻게 숨기나요?

이것에 대한 코드를 어떻게 제공해야 할지 모르겠습니다.

enter image description here

네, 가능합니다(이 페이지 하단의 업데이트 참조).

WooCommerce 템플릿 재정의(WooCommerce 플러그인 폴더를 활성 하위 테마 또는 테마로 복사, 이름 변경).
이를 위해서는 먼저 관련 문서를 꼭 읽어주시기 바랍니다.

위의 작업을 올바르게 수행한 후에는 활성 하위 테마 또는 테마 안에 있는 폴더에 있는 템플릿 2개를 편집해야 합니다.파일 위치:

  1. emails (sub folder) > email-addresses.php (php file).

    이 템플릿의 코드를 19행에서 바꿉니다.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">
    <tr>
        <td class="td" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
            <h3><?php _e( 'Billing address', 'woocommerce' ); ?></h3>

            <p class="text"><?php echo $order->get_formatted_billing_address(); ?></p>
        </td>
        <?php // ======================> Here begins the customization

            $shipping_local_pickup = false;
            if ( $items_totals = $order->get_order_item_totals() ) {
                foreach ( $items_totals as $items_total ) {
                    if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
                }
            }
            // End

            if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) : ?>
            <td class="td" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" valign="top" width="50%">
                <h3><?php _e( 'Shipping address', 'woocommerce' ); ?></h3>

                <p class="text"><?php echo $shipping; ?></p>
            </td>
        <?php endif; ?>
    </tr>
</table>
  1. emails (sub folder) > plain (sub folder) > email-addresses.php (php file).

    이 템플릿의 코드를 19행에서 바꿉니다.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

echo "\n" . strtoupper( __( 'Billing address', 'woocommerce' ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $order->get_formatted_billing_address() ) . "\n";

 // ======================> Here begins the customization

$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
    foreach ( $items_totals as $items_total ) {
        if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
    }
} // End

if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) && !$shipping_local_pickup ) {
    echo "\n" . strtoupper( __( 'Shipping address', 'woocommerce' ) ) . "\n\n";
    echo preg_replace( '#<br\s*/?>#i', "\n", $shipping ) . "\n";
}

주문에서 로컬 픽업이 사용되는 경우를 감지하기 위해 이 항목을 추가했습니다.

$shipping_local_pickup = false;
if ( $items_totals = $order->get_order_item_totals() ) {
    foreach ( $items_totals as $items_total ) {
        if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
    }
}

그리고 배송 주소의 표시를 중지하기 위한 기존 문구(로컬 픽업의 경우):

&& !$shipping_local_pickup

업데이트: ** WC_Abstract_Order 클래스 - ** 메서드를 사용하여 훨씬 압축적인 코드를 사용할 수 있습니다.

$shipping_local_pickup = false;
if ( $order->has_shipping_method( 'local_pickup' ) )
    $shipping_local_pickup = true;

그리고 배송 주소의 표시를 중지하기 위한 기존 문구(로컬 픽업의 경우):

&& !$shipping_local_pickup

참조:

언급URL : https://stackoverflow.com/questions/38936283/hide-shipping-address-on-local-pickup-in-woocommerce-email-notifications

반응형