Home>Support>I crash my site! Help please!

I crash my site! Help please!

By Eric, 10 years ago. Last reply by Andrew Misplon, 10 years ago.
Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi
I been adding a custom field to the checkout page in Woocomerce av it worked fine.
But when adding a code to make this new custom field to inserted in the order email it craches my site totally.
Now i just get this message:
Parse error: syntax error, unexpected T_STRING in /home/wentorse/public_html/spatunnan.se/wp-content/themes/vantage-child/functions.php on line 78

Please help :-)

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 10 years, 3 months ago Andrew Misplon
    Hi, I Work Here

    Hi Eric

    No worries, this should be an easy fix. Even a tiny error in functions.php will cause this to happen. Do you have FTP access? If so, go to /wp-content/themes/vantage-child/ and download functions.php to your desktop. Then copy the contents here and I’ll take a look at what’s causing that error.

  2. 10 years, 3 months ago Eric
    <?php/** * Enqueue the parent theme stylesheet. */add_action( 'wp_enqueue_scripts', 'vantage_parent_style' );function vantage_parent_style() {    wp_enqueue_style( 'parent-theme', get_template_directory_uri() . '/style.css' );}/** * Enqueue the child theme stylesheet. */add_action( 'wp_enqueue_scripts', 'vantage_child_style', 20 );function vantage_child_style() {    wp_enqueue_style( 'child-theme', get_stylesheet_uri() );}/** * Set the child theme text domain. */function vantage_child_set_text_domain(){load_theme_textdomain( 'vantage', get_stylesheet_directory() . '/languages' );}add_action('after_setup_theme', 'vantage_child_set_text_domain', 15);/*** Add the field to the checkout**/add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');function my_custom_checkout_field( $checkout ) {echo ''.__('Personnummer obligatoriskt för fakturering,').'';woocommerce_form_field( 'my_field_name', array('type'          => 'text','class'         => array('my-field-class form-row-wide'),'label'         => __('10 siffror ÅÅMMDD-NNNN'),'placeholder'       => __('Ditt personnummer, 10 siffror ÅÅMMDD-NNNN'),), $checkout->get_value( 'my_field_name' ));echo '';}/*** 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_field_name'])$woocommerce->add_error( __('Please enter something into this new shiny field.') );}/*** 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_field_name']) update_post_meta( $order_id, 'My Field', esc_attr($_POST['my_field_name']));}/*** Add the field to order emails**/add_filter(‘woocommerce_email_order_meta_keys’, ‘my_custom_checkout_field_order_meta_keys’);function my_custom_checkout_field_order_meta_keys( $keys ) {$keys[] = ‘My Field';return $keys;}
  3. 10 years, 3 months ago Andrew Misplon
    Hi, I Work Here

    Thanks Eric.

    I think we lost line spacing so I’m not sure which was the line causing this. Let’s quickly focus on this last function. Two things:

    Question One

    Please check the inverted commas in this function. See how in the function above it, the inverted commas are very straight but in this last function they are angled:

    Correct inverted commas:

    add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');

    Incorrect inverted commas:

    add_filter(‘woocommerce_email_order_meta_keys’, ‘my_custom_checkout_field_order_meta_keys’);

    With correct inverted commas, this is how this last function should look:

    /*** Add the field to order emails**/add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');function my_custom_checkout_field_order_meta_keys( $keys ) {$keys[] = 'My Field';return $keys;}

    Question Two

    Does My Field match up to the field you’ve added?

    Here are two threads discussing this function:

    https://gist.github.com/mikejolley/2263203
    https://gist.github.com/mikejolley/1547491

  4. 10 years, 3 months ago Eric

    Hi Andrew! Thanks for your assistance! I am so impressed over your support!

    One detail. In the mail the information in this custom field is the customers social security number coming with a header “My Field:” folowed by thesocial security number.
    In witch line do I change “My Field:” to my own header text “Personnummer:” ?

  5. 10 years, 3 months ago Andrew Misplon
    Hi, I Work Here

    For sure :) Glad to hear we’re making progress.

    Looking over the functions file I see what you were trying to do there. Before we proceed and trouble shoot this I thought I’d mention this option:

    http://www.woothemes.com/products/admin-custom-order-fields/
    http://docs.woothemes.com/document/woocommerce-admin-custom-order-fields/

    I know it’s not cheap but it would make this pretty easy.

    Perhaps take a look and see if it would do what you require and if the cost is acceptable.

    Alternatively I’ll try setup the above in my local child theme and see if I can’t get things working.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More