• Resolved Jarryd

    (@jizzrage)


    I’ve been trying to enqueue a script file to my footer and it was working fine when I was using the hook wp_enqueue_scripts. I noticed that some scripts were being added to the hook woo_foot and I want my script to be the very last script added to the document, so I’ve been trying to hook into that with no success. I’ve tried both woo_foot and woo_footer_after with no success, and also tried using woo_do_atomic instead of add_action.

    I could be misunderstanding as I’ve just recently been trying to use action and filter hooks more often.

    In my functions.php file:

    if ( function_exists( 'woo_foot' ) ) {
    	// This fires, tested an echo here
    	add_action( 'woo_foot', 'custom_footer_scripts' );
    } else {
    	// Fallback if Woocommerce functionality is removed
    	add_action( 'wp_enqueue_scripts', 'custom_footer_scripts', 9999 );
    }
    function custom_footer_scripts() {
    	// Not firing
    	wp_enqueue_script(
    		'custom-js',
    		get_bloginfo( 'template_url' ).'/includes/js/custom.js',
    		array( 'jquery' ),
    		'1.0',
    		true
    	);
    }

    https://www.ads-software.com/extend/plugins/woocommerce/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Roy Ho

    (@splashingpixelscom)

    Just use dependencies.. So fine the handle of the last script you want to load after.

    So say the handle was named “woo-end”.

    You then only need to do this:

    // assuming you only need this in frontend
    if ( ! is_admin() )
         wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/includes/js/custom.js', array( 'jquery', 'woo-end' ), '1.0', true );
    Thread Starter Jarryd

    (@jizzrage)

    Ah nice! Thanks for that, worked just fine ?? I didn’t realise that specifying dependencies changed the order! Makes sense lol.

    In this case the last script loaded is ‘thickbox’. So in the instance that thickbox gets removed, my custom.js would be remove also (I think?).

    Is there any way around this or would I change the dependency?

    I ask this just in-theory because it’s literally the only script that was being loaded after my hook.

    Roy Ho

    (@splashingpixelscom)

    No, it would not remove your script…it would simply load in a different order based on the the next dependency…But may I ask why you need it to be at the very end?

    Thread Starter Jarryd

    (@jizzrage)

    Oh that’s good then :).

    In the instance that I need to write a thickbox script that loads on DOM ready, the Thickbox script might have not loaded yet.

    I prefer to have my custom scripts file be the last thing to make sure all my jQuery plugins/other scripts load first.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can't add_action to 'woo_foot' hook’ is closed to new replies.