• Hi

    I have noticed that the following php error is showing with this attachment:

    Function wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the wcoa-front-app handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.)

    The only way it works is if I remove the plugin but I need this plugin. Is there any other way

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Dominik

    (@sldesignpl)

    Hello,

    I am testing the ‘Order Attachments for WooCommerce’ plugin on the latest version of WordPress, which is 6.2.2, and the issue you described does not occur for me.

    I will try to look into it and debug the problem on my end. Maybe I will be able to identify and fix something. In the meantime, please follow these steps:

    Keep the ‘Order Attachments for WooCommerce’ plugin enabled.
    Disable other plugins one by one until my plugin starts functioning correctly. This way, we might be able to find the culprit. Unless the issue lies within the theme? You should also check that.
    Thank you!

    Thread Starter sunnydhain1

    (@sunnydhain1)

    Hi,

    I have updated the themes and all other plugins and the error is still showing? Did you manage to find anything?

    The error persists and it is because you are calling wp_enqueue_style in the class __construct of WCOA_My_Account. This is wrong, it needs to be called during specific hooks before rendering.

    There are two solutions for this issue:

    Use wp_enqueue_scripts hook

    public function __construct()
    {
        add_action( 'wp_enqueue_scripts', [$this, 'enqueue'] );
    }
    
    public function enqueue()
    {
        wp_enqueue_style( 'wcoa-front-app', WCOA_PLUGIN_URL . '/assets/frontend/css/style.css', false, 1.0, 'all' );
    }

    Use it before rendering your template

    public function initialize_template()
    {
        wp_enqueue_style( 'wcoa-front-app', WCOA_PLUGIN_URL . '/assets/frontend/css/style.css', false, 1.0, 'all' );
        do_action( 'wcoa_account_attachments_enqueue' );
        require_once WCOA_PLUGIN_DIR . 'templates/frontend/frontend-my-account-attachments.php';
    }

    In my personal opinion, I would go with the second option, this way you don’t have to load the css on every single page which is not optimal, the other workaround would be to use the wp_enqueue_scripts hook but only enqueue the style when the attachment page is being rendered.

    Came here to report the same php errors. The above suggestion by @pirulee is the way to go, looks like you have already done this in class-wcoa-admin.php so should be an easy fix.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error Help’ is closed to new replies.