할인 스크립트 예

이 예는 품목 스크립트를 사용하여 고객의 국가를 기준으로 할인을 제공합니다. 또한 고객에게 할인 정보를 제공하는 Liquid 코드 예도 포함되어 있습니다. 이 예에서는 스토어의 checkout.liquid 파일에 대한 액세스 권한이 필요합니다. 테마 코드에서 이 파일에 대한 액세스 권한이 없는 경우 Checkout ExtensibilityShopify Functions를 사용하여 결제를 사용자 지정하십시오.

이 예는 다음 규칙이 적용되는 가상의 VAT 세금을 사용합니다.

  • 연합 국가에 거주하는 고객에게는 판매된 모든 제품에 대해 VAT 세금이 부과됩니다.
  • 제품을 구매하여 비연합 국가로 수출하는 고객은 VAT 세금을 납부할 필요가 없습니다. 즉, 이러한 고객에 대한 판매는 부가가치세가 면제됩니다.
  • 스토어의 제품 가격에는 VAT 세금이 포함됩니다. 즉, 스토어의 세금 설정에 대해 모든 세금이 가격에 포함됨 설정이 활성화되어 있습니다.

상점에서 모든 고객에게 표시되는 제품 가격에는 VAT가 포함되어 있습니다. 카트에 품목이 추가되면 VAT 포함 가격이 표시됩니다.

Cart with tax applied

결제 시에는 스크립트에서 배송 국가가 확인됩니다. 해당 국가가 비연합 국가인 경우에는 총 가격이 VAT 금액만큼 감소합니다.

세금이 제거된 카트

다음 예시에서는 고객의 국가가 확인됩니다. 고객이 VAT가 적용되지 않는 국가에 거주하는 경우에는 주문 총 가격이 VAT 금액만큼 감소합니다.

# Set VAT equal to the amount of the VAT rate.
# For example, if the VAT rate is 20%, then VAT=20
VAT = 20

# Message that appears beside the discount in the checkout
VAT_REMOVAL_MESSAGE = "VAT removed"

# List of countries where the VAT is charged to orders
COUNTRY_CODES_EU = %w[
AT BE BG CY CZ DK EE FI FR DE GR HU IE IT
LV LT LU MT NL PL PT RO SK SI ES SE GB
]

if Input.cart.shipping_address
  unless COUNTRY_CODES_EU.include?(Input.cart.shipping_address.country_code)
    Input.cart.line_items.each do |line_item|
      product = line_item.variant.product
      next if product.gift_card?
      vat_only_fraction = VAT / (100.0 + VAT)
      vat = line_item.line_price * vat_only_fraction
      ex_vat_price = line_item.line_price - vat
      line_item.change_line_price(ex_vat_price, message: VAT_REMOVAL_MESSAGE)
    end
  end
end

Output.cart = Input.cart

다음 Liquid 코드는 위의 스크립트와 함께 작동하여 카트의 변경 사항을 설명합니다.

다음 코드를 checkout.liquid에 추가합니다.

<style>
  .checkout__vat-exemption-message {
    padding: 1.25em 0;
    display: none;
  }
  @media (min-width: 1000px) {
    .checkout__vat-exemption-message {
      padding-top: 0;
      padding-bottom: 2.5em;
    }
  }
</style>

<div class="checkout__vat-exemption-message">
  <span>{{ 'plus.checkout.vat_exemption_message' | t }}</span>
</div>

<script>
  $(document).on('ready page:load page:change', function() {
    var country = '';

    if(Shopify.Checkout.step === 'contact_information') {
      $country = $('[data-step] select[name="checkout[shipping_address][country]"]');
      country = $country.find(':selected').data('code');
    } else {
      country = "{{ checkout.shipping_address.country_code }}";
    }

    var eu_countries = ['AT','BE','BG','CY','CZ','DK','EE','FI','FR','DE','GR','HU','IE','IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','ES','SE','GB'];

    if (eu_countries.includes(country)) {
      $('.checkout__vat-exemption-message').css('display', 'none');
    } else {
      $('.checkout__vat-exemption-message').css('display', 'block');
    }
  });

</script>

영어 로캘 파일에 다음 코드를 추가합니다.

"plus":{
    "checkout": {
      "vat_exemption_message": "As we're shipping outside the EU the VAT has been removed from items in your cart."
    }
  }

이 페이지의 정보

자세히 알아보기

자세한 정보 알아보기:

Shopify와 함께 사업을 시작할 준비가 되셨습니까?

무료 체험