무게가 224kg 이상인 경우 Woocommerce Checkout에 알림 표시 [중복]
Nov 19 2020
비슷한 답변을 몇 개 보았지만 필요한 것은 아닙니다. 기본적으로 총 주문 중량이 225kg 이상인 경우 결제시 표시 할 알림 만 표시하고 싶습니다.
디스플레이 무게 및 woocommerce 카트 및 결제 응답 코드 의 남은 무게 메시지를 기반으로 한 내 적응 코드는 다음과 같습니다.
// Display a custom shipping message when cart weight exeeds a limit
add_filter( 'woocommerce_before_cart', 'display_total_weight_notice' );
add_filter( 'woocommerce_before_checkout_form', 'display_total_weight_notice' );
function display_total_weight_notice( $message ) { // DEFINE the allowed weight limit $cart_total_weight = WC()->cart->get_cart_contents_weight();
if( cart_total_weight >= 225 ) :
wc_print_notice( sprintf(
__( 'Your order has a total weight of %s. This will be shipped via Pallet Delivery, by continuing you agree to the following:<br><br>
> Ground/Road around the property will be flat, level and solid. <br>
> Standard Delivery will take place between 9am-5pm and will require a signature. You can advise a safe place to leave your order, however this is at the driver’s discretion to do so, we hold no responsibility if left. <br>
> Where a delivery cannot be made due to access, a re-delivery can be made at your request for a charge of £45.00 per pallet on the following day or when arranged. <br>
> In any cases of Damages/Shortages you will note this on the delivery note when you Sign for it, and then contact us right away. No refunds/replacements will be given if damages are not noted at delivery. <br>
> Pallet Orders cancelled en route, or returned due to ground Conditions/Access Restrictions will incur a return fee of £45 per pallet (subject to location), deducted from any refunds given. <br>
> Orders over 1000kg will require your own forklift.
' ),
'<strong>' . wc_format_weight($cart_total_weight) . '</strong>',
),'notice' );
endif;
}
그러나 그것은 나를 위해 작동하지 않습니다.
답변
2 Mtxz Nov 19 2020 at 19:10
방금 코드를 테스트했는데 카트 페이지에 메시지가 올바르게 표시됩니다.
코드에 오타가 있고 $
앞에 변수가 누락되었습니다 .
if( $cart_total_weight >= 225 ) :
무게가있는 제품을 하나 이상 설정할 때에서 정확한 총 무게를 얻습니다 $cart_total_weight = WC()->cart->get_cart_contents_weight();
. 정의 된 무게로 장바구니에 제품이없는 경우 올바르게 0을 반환합니다.
카트 템플릿을 편집하지 않은 경우 작동합니다. 편집 한 경우이 do_action()
여전히 여기에 있는지 확인 하십시오.

여기에서는 기준에 맞게 25Kg의 제품으로 메시지를 표시하기 위해 한계를 20kg으로 편집했습니다.