How can I specifically enqueue scripts for edit orders pages only

Question

The problem is that enqueing script this way, I end up inadvertently targeting product pages and other pages also which use the post and post-new hook, as WordPress has many types of posts, not only orders. I only want to target Woocommerce view individual order and create new order admin pages. (Not orders list, just individual orders.)

function selectively_enqueue_admin_script_js_for_edit_address( $hook ) {
    if ( 'post.php' != $hook and 'post-new.php' != $hook ) {
        return;
    }
    wp_enqueue_script( 'artio-wc-admin-order-page-mod', '/wp-content/plugins/custom_wc_mods/order_page/paste_payment_instructions_and_prompts_into_shipping_address_form_v2.js', array(), date("h:i:s") );
    /* https://stackoverflow.com/a/31834007 */
    /* During development, you could avoid the hassle of clearing the browser cache by passing a dynamic variable as the file's version when you enqueue it. For instance, the current time. */
}
add_action( 'admin_enqueue_scripts', 'selectively_enqueue_admin_script_js_for_edit_address' );

0
ptrcao 6 days 2023-01-21T19:28:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse