This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

“Fatal error: Call to undefined method WooCommerce::add_error() in …………………..

Resolved 20 replies premiumthemetheme-vantage
10 years ago · Last reply by Andrew Misplon 10 years ago

Hi,
From Yesterday our customers can not send their orders thru the webshop. This error messages is displayed in the checkout?
“Fatal error: Call to undefined method WooCommerce::add_error() in /home/badbanco/public_html/wp-content/themes/vantage-child/functions.php on line 61”

It this something you can help me with?

// Eric

URL: http://www.badbaljan.com/till-kassan/

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

20
  1. Magus Staff 10 years, 8 months ago

    Hi Eric

    This is being caused by some code you have placed into your child theme’s functions.php file. If possible please post the content of your child functions file here using the code tags as described below the reply box.

    Thanks

    Magus

  2. Eric 10 years, 8 months ago
    <?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 '<div id="my_custom_checkout_field"><span>'.__('Personnummer obligatoriskt för fakturering,').'</span>';
    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 '</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_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. Magus Staff 10 years, 8 months ago

    Hi Eric

    The issue seems to be the add_error entry in this function

    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.') );
    }

    This option has now been deprecated please change this function to

    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_notice( __('Please enter something into this new shiny field.') );
    }

    If you are using this option in any other functions you should also change it there

    Magus

  4. Eric 10 years, 8 months ago

    Hi,
    Do you know how I can change this field setting so its not a mandatory field just a optional field?

    Eric

  5. Magus Staff 10 years, 8 months ago

    Hi Eric

    If you do not want this field to be mandatory you could just leave out the above function. This function checks for content, prompting the user to enter something if empty. If you leave out the function the check will not be made, allowing the update to continue even if nothing is in the field.

    Magus

  6. Eric 10 years, 5 months ago

    Hi,
    Can we pick up this thread were we left of? I haven’t had the time or the courage to try to go into this without some more guidance. I would like to take away the mandatory on this field were costumers can add their social security number.
    Can you please guide me witch row I should remove or change?

    Eric

  7. Andrew Misplon Staff 10 years, 5 months ago

    Hi Eric

    Can you send ZIP your child theme, upload it to the Media Library and send me the link so I can see where we are?

    Thanks

  8. Eric 10 years, 5 months ago

    Hi Andrew,
    Do you mean to my WP media library? Is it not something in the child theme’s functions.php file as mentioned above?

  9. Andrew Misplon Staff 10 years, 5 months ago

    I’d ideally like to check your child theme out. Can you send it me? Lots of ways to do it, above was one option. What I left out was, you’d need to access your server via FTP or hosting File Manager, go to /wp-content/themes/ download “vantage-child” to your desktop. ZIP it. Then, to send it to me, upload it to your Media Library and send me the link so I can download it.

  10. Eric Private 10 years, 5 months ago

    This is a private message.

  11. Andrew Misplon Staff 10 years, 5 months ago

    All we need to do is added:

    required => false,

    To your custom field.

    Ref: http://www.portmanteaudesigns.com/blog/2015/02/04/woocommerce-custom-checkout-fields-email-backend/

    I’ve made this change, here is your child theme updated:

    https://siteorigin.com/wp-content/uploads/2015/09/vantage-child-eric-02.zip

    Ideally just replace your child functions.php with the new one I’ve just sent. I haven’t tested that file live so it’s important you have FTP access ready in case you need to upload the backup functions.php file.

  12. Eric 10 years, 5 months ago

    Many thank Adrew & co!
    I will try this!

    Eric

  13. Andrew Misplon Staff 10 years, 5 months ago

    For sure :)

  14. Eric 10 years, 4 months ago

    Hi! I hope you all are fine?! I took courage and time to replace the functions.php file you gave me. But this error message comes:
    ” Fatal error: Call to undefined method WooCommerce::add_error() in /home/badbanco/public_html/wp-content/themes/vantage-child/functions.php on line 51 “

  15. Andrew Misplon Staff 10 years, 4 months ago

    Hi Eric

    Perhaps we can take a step back and find another way to achieve the functionality you’ve tried to add in your child theme functions file. Can you confirm what you’ve added to the child theme functions file in terms of functionality?

  16. Eric 10 years, 4 months ago

    The function is in the woocomerce checkout page and their is three different payment ways to chose:
    First id by a 20 day invoice after delivery, in that case the customers must fill in this extra added field with their social security number. To be able to do a credit check.
    The second alternative is prepayment before dispatch and here is should it not me mandatory to enter their social security number. And its here the error message comes the last three month if costumers don’t enter something in the social security number field. Prior that it worked.
    The third payment alternative is: Payment in our store with visa or master card on pickup and without something in written in the social security number field the error message comes.

  17. Andrew Misplon Staff 10 years, 4 months ago

    Ideally we’d find a plugin solution to assist with the above. We do our best to assist and advise with minor custom development tweaks, I think we’ve gone past that normal mark here. Let me take a quick look around and see what I can find.

  18. Andrew Misplon Staff 10 years, 4 months ago

    It’s a premium plugin but at a glance this looks like it would resolve the challenges you’re facing:

    http://www.woothemes.com/products/woocommerce-checkout-field-editor/

    Here is the documentation for the plugin:

    https://docs.woothemes.com/document/checkout-field-editor/

  19. Eric 10 years, 4 months ago

    Ok. I will try this. Many thanks for your help

  20. Andrew Misplon Staff 10 years, 4 months ago

    For sure, hopefully it can achieve everything you’re after and more.

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.

Have a different question or issue?

Start New Thread