할인 스크립트 예시
이 예시에서는 품목 스크립트를 사용하여 고객의 국가에 따라 할인을 제공합니다. 또한 고객에게 할인 관련 정보를 제공하기 위한 Liquid 코드 예시도 포함되어 있습니다. 이 예시를 사용하려면 스토어의 checkout.liquid 파일에 액세스할 수 있어야 합니다. 테마 코드에서 이 파일에 액세스할 수 없는 경우에는 Shopify Extensions for checkout 및 Shopify Functions를 사용하여 체크아웃을 맞춤 설정하십시오.
이 예시에서는 다음 규칙을 따르는 가상의 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."
}
}이 페이지의 내용
자세히 알아보기
다음에 대해 자세히 알아보기: