-1

I am trying to add a custom field to the cart page, and as it says in their documentation it seems to be easy to add custom field to checkout pages like shipping and billing. But I would like to add a field to the cart page. So, on my page I have woocommerce shortcode:

[woocommerce_cart]

I should be adding a field to the woocommerce cart, so creating child theme wouldn't work, from what I could read, because that would only change other sections of the page, and I need to add the field to the woocommerce cart, but how can I do that?

I have tried by adding this code snippet to the functions file of my theme Enfold.

functions-enfold.php:

* Add the field to the checkout
**/
add_action('woocommerce_cart_collaterals', 'my_custom_checkout_field');

function my_custom_checkout_field() {
echo '<div id="my_custom_checkout_field"><h2>'.__('My Field').'</h2>';

woocommerce_form_field( 'my_field_name', array(
'type'          => 'text',
'class'        => array('my-field-class form-row-wide'),
'label'        => __('Fill in this field'),
'placeholder'      => __('Enter something'),
));

echo '</div>';

}

But I got an error:

Parse error: syntax error, unexpected '*' in /nas/content/staging/bokashinorge/wp-content/themes/enfold/functions-enfold.php on line 1795

Even on deleting the code snippet and updating the file again, I was still getting the same error, and now I seem to locked because on refresh I keep getting the error all the time, and can't edit anything in the dashboard. How can I fix this, and add the field without getting errors?

Leff
  • 1,968
  • 24
  • 97
  • 201

1 Answers1

1

Try to add / before * at the first line, like this:

/* Add the field to the checkout **/

Alex
  • 2,707
  • 4
  • 29
  • 42
  • The problem is that I can't seem to edit anything in the dashboard now. I saw that ftp is the only way to fix this? – Leff Nov 21 '16 at 11:37
  • Yes, you must enter to your webserver via FTP and edit this file. Or cPanel file manager maybe. – Alex Nov 21 '16 at 11:38
  • and adding the field to the cart page will work if I just edit the functions.php file of my theme, like I did it in my question? – Leff Nov 21 '16 at 11:42
  • I think yes, if you correctly copied the code from [documentation](https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/). – Alex Nov 21 '16 at 11:56