/**
* Show international customs disclaimer checkbox at WooCommerce checkout
* Displays for all countries EXCEPT United States (US)
*/
// Add the checkbox field to checkout
add_action( 'woocommerce_review_order_before_submit', 'idesign_international_customs_checkbox' );
function idesign_international_customs_checkbox() {
$chosen_country = WC()->customer->get_shipping_country();
// Fallback to billing country if shipping country is not set
if ( empty( $chosen_country ) ) {
$chosen_country = WC()->customer->get_billing_country();
}
// Only show for non-US countries
if ( $chosen_country === 'US' ) {
return;
}
?>
'checkbox',
'label' => __( 'I understand that international shipments may be delayed, held, or rejected by cust
oms in my country and refunds cannot be guaranteed. I accept this liability.', 'woocommerce' ),
'required' => true,
), WC()->checkout->get_value( 'international_customs_accept' ) );
?>
customer->get_shipping_country();
if ( empty( $chosen_country ) ) {
$chosen_country = WC()->customer->get_billing_country();
}
// Only validate for non-US countries
if ( $chosen_country === 'US' ) {
return;
}
if ( empty( $_POST['international_customs_accept'] ) ) {
wc_add_notice(
__( 'Please acknowledge the international shipping disclaimer to complete your order.', 'woocommerce' ),
'error'
);
}
}
// Save the checkbox value to th
e order meta
add_action( 'woocommerce_checkout_update_order_meta', 'idesign_save_international_customs_checkbox' );
function idesign_save_international_customs_checkbox( $order_id ) {
if ( ! empty( $_POST['international_customs_accept'] ) ) {
update_post_meta( $order_id, '_international_customs_accept', '1' );
}
}
// Re-render checkbox dynamically when country is changed (AJAX update)
add_filter( 'woocommerce_checkout_fields', 'idesign_customs_checkbox_country_refresh' );
function idesign_customs_che
Skip to content