Skip to content

Instantly share code, notes, and snippets.

@Niloys7
Created April 2, 2025 11:29
Show Gist options
  • Save Niloys7/41a77b498de64805df6f98091d847951 to your computer and use it in GitHub Desktop.
Save Niloys7/41a77b498de64805df6f98091d847951 to your computer and use it in GitHub Desktop.
Show a custom checkbox before the "Place Order" button on the checkout page if the cart contains deposit items.
<?php
// Add the required checkbox right before the "Place Order" button
// plugin: https://www.codeixer.com/woocommerce-deposits-plugin/
add_action('woocommerce_review_order_before_submit', 'custom_checkout_terms_checkbox', 9);
function custom_checkout_terms_checkbox() {
if(!cidw_cart_have_deposit_item()){
return;
}
?>
<p class="form-row terms-field" style="margin-bottom: 15px;">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox" name="custom_terms" id="custom_terms">
I agree to the <strong><a href="#" target="_blank">Deposits Terms & Conditions</a></strong>.
</label>
</p>
<?php
}
// Validate the checkbox before order submission
add_action('woocommerce_checkout_process', 'custom_checkout_validate_terms_checkbox');
function custom_checkout_validate_terms_checkbox() {
if(!cidw_cart_have_deposit_item()){
return;
}
if (!isset($_POST['custom_terms'])) {
wc_add_notice(__('You must agree to the Deposit Terms & Conditions before placing your order.'), 'error');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment