cysus
cysus

Reputation: 143

Add custom javascript to Woocommerce edit product page

how can I reference a custom js-file only to the Woocommerce edit / add product page?

Thanks in advance.

Ciao

Upvotes: 1

Views: 2562

Answers (1)

cysus
cysus

Reputation: 143

This worked for me (to be added in themes's functions.php file):

//wholesale-prices
function add_admin_scripts( $hook ) {

    global $post;

    if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
        if ( 'product' === $post->post_type ) {     
            wp_enqueue_script(  'myscript', get_stylesheet_directory_uri().'/js/wholesale-prices.js' );
        }
    }
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 );

Upvotes: 2

Related Questions