Skip to content

Instantly share code, notes, and snippets.

@melvinstanly
Created September 12, 2018 06:52
Show Gist options
  • Save melvinstanly/e042ee401e1afab72fcad4f4ed8f96d4 to your computer and use it in GitHub Desktop.
Save melvinstanly/e042ee401e1afab72fcad4f4ed8f96d4 to your computer and use it in GitHub Desktop.
Add custom field or html to review order table in WooCommerce Checkout
<?php
/* To add custom field in order review table in checkout page, you will have to use some of the hooks listed below.
do_action( 'woocommerce_review_order_before_cart_contents' );
do_action( 'woocommerce_review_order_after_cart_contents' );
do_action( 'woocommerce_review_order_before_shipping' );
do_action( 'woocommerce_review_order_after_shipping' );
do_action( 'woocommerce_review_order_before_order_total' );
do_action( 'woocommerce_review_order_after_order_total' );
So basically if content is passed to any hook in the review-order.php template, then the HTML is duplicated
when the cart order totals are reloaded.
This is because this table is replaced via JS after updating, but if you've inserted non-table content via these hooks
it will be moved out of the table as it's invalid.
All of the action hooks listed need table rows since hooks are within a HTML table/tbody.
*/
add_action( 'woocommerce_review_order_after_order_total', 'checkout_review_order_custom_field' );
function checkout_review_order_custom_field() {
echo '<tr><td>Text here</td><td>';
woocommerce_form_field( 'my_split_checkbox', array(
'type' => 'checkbox',
'class' => array('checkbox_field'),
'label' => __('', 'woocommerce'),
'required' => false,
));
echo '</td></tr>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment