a little help to find a simple error, but I didn’t know php code.
I’ve paste a tested code exactly in the indicated point function.php and I produce this error:
Which is asking to me to modify?
I don’t understand, I pass you text I paste in it.
What’s wrong???
Fatal error: Cannot redeclare my_custom_checkout_field() (previously declared in /var/www/vhosts/lococostyle.com/httpdocs/wp-content/themes/royal/functions.php:19) in /var/www/vhosts/lococostyle.com/httpdocs/wp-content/themes/royal/framework/theme-functions.php on line 1376
/**
* Add checkbox field to the checkout
**/
add_action(‘woocommerce_after_checkout_registration_form’, ‘my_custom_checkout_field’);
function my_custom_checkout_field( $checkout ) {
echo ‘<div id=”my-new-field”><h3>’.__(”).'</h3>’;
woocommerce_form_field( ‘my_checkbox’, array(
‘type’ => ‘checkbox’,
‘class’ => array(‘input-checkbox’),
‘label’ => __(‘Buyer (recipient) will be responsible for all customs fees, duties and import charges that are levied at time of delivery. Each country has their own customs rules and regulations so check on your own countries allowances and regulations if you’re unsure. Please, make sure your revise these costs before purchasing, we are not held responsible after order has been processed and has arrived to its respective destination.’),
‘required’ => true,
), $checkout->get_value( ‘my_checkbox’ ));
echo ‘</div>’;
}
/**
* Process the checkout
**/
add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field_process’);
function my_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST[‘my_checkbox’])
wc_add_notice(‘You have to check all the alertbox in the page! Please check it and try again.’, ‘error’ );
}
/**
* Update the order meta with field value
**/
add_action(‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’);
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST[‘my_checkbox’]) update_post_meta( $order_id, ‘My Checkbox’, esc_attr($_POST[‘my_checkbox’]));
}
Our mission is to help Internet businesses and their customers interact in a way that mirrors real-world customer experience: personal, human, and fun.
Upload your translation files
Lorem ipsum dolor sit amet consectetur adipisicing elitsed do
Love us as much as we love you?
If you love XStore theme and have something nice to say
don’t hesitate to tell about this! We’d appreciate if you could take a moment to give us 5-stars!