• Resolved Dana Harrison

    (@danaharrison)


    This function appears to work perfectly when called directly (from my cart page) – it displays a custom notice as-called. However, when trying to log in to wp-admin as an Administrator, with this code present in functions.php (not even being called, just present), I’m hit with an HTTP 500. Only solution has been to totally comment out this function. Any suggestions?

    Code:

    add_action( 'woocommerce_init', 'sa_custom_notice' );
    if (!function_exists('sa_custom_notice')) {
            function sa_custom_notice( $_msg, $_msgtype ) {
                    global $woocommerce;
                    wc_add_notice( $_msg, $_msgtype );
            }
    }

    Error in debug.log:

    Undefined variable: _msgtype in /var/www/html/wordpress/wp-content/themes/spacious/functions.php on line 724

Viewing 2 replies - 1 through 2 (of 2 total)
  • Mike M. a11n

    (@mikedmoore)

    Automattic Happiness Engineer

    Hi there,

    I believe the problem is the woocommerce_init hook you’re using. You’ll likely want to use a hook that is only called on the page where this notice is needed.

    Joel Williams

    (@joelwills)

    Automattic Happiness Engineer

    Hi there!

    There hasn’t been a reply for a while so I’m going to close this ticket.

    If you’re still having problems please open a new ticket, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom wc_add_notice function throws error in wp-admin’ is closed to new replies.