This code correctly works but does not place the custom field where I want it. In the add_action
I would like to use woocommerce_review_order_after_order_total
as the location attribute to place it on the page. I got the hook name from this visual guide / However this hook breaks my code and gives me the following php error.
Fatal error: Uncaught Error: Call to a member function get_value() on string in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/themes/salient-child/functions.php on line 96
Hopefully someone can give me hand. Thanks
/**
* Add custom field to the checkout page
*/
add_action('woocommerce_after_order_notes', 'custom_checkout_field');
/* add_action('woocommerce_review_order_after_order_total', 'custom_checkout_field');*/
/* ^ This is the code that is breaking */
function custom_checkout_field($checkout)
{
echo '<div id="custom_checkout_field"><h2>' . __('New Heading') . '</h2>';
woocommerce_form_field('custom_field_name', array(
'type' => 'text',
'class' => array(
'my-field-class form-row-wide'
) ,
'label' => __('Custom Additional Field') ,
'placeholder' => __('New Custom Field') ,
) ,
$checkout->get_value('custom_field_name'));
echo '</div>';
}