diff --git a/assets/js/scripts.js b/assets/js/scripts.js index f919331..9ea5cdd 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -2,31 +2,35 @@ jQuery( function( $ ) { $( document ).on( 'change', '.post-type-shop_order select[name="action"], .post-type-shop_order select[name="action2"], .woocommerce_page_wc-orders select[name="action"], .woocommerce_page_wc-orders select[name="action2"]', function ( e ) { e.preventDefault(); - let actionSelected = $( this ).val(); + let actionSelected = $( this ).val(); + const $emailSelection = $( '.wpo_bewc_email_selection' ); + if ( 'wpo_bewc_send_email' === actionSelected ) { - $( '#wpo_bewc_email_selection' ) - .show() - .insertAfter( '#wpbody-content .tablenav-pages' ) - .css( { - 'display': 'block', - 'clear': 'left', - 'padding-top': '6px', - } ) - .closest( 'body' ).find( '.wp-list-table' ).css( { - 'margin-top': '50px', + + // Move the element to the correct location if it's not. + if ( ! $emailSelection.parent().is( '.tablenav' ) ) { + $emailSelection.insertAfter( '#wpbody-content .tablenav-pages' ).css( { + 'display': 'block', + 'clear': 'left', + 'padding-top': '6px', } ); + } + + $emailSelection.show().closest( 'body' ).find( '.tablenav' ).css( { + 'height': 'auto', + } ); } else { - $( '#wpo_bewc_email_selection' ).hide().closest( 'body' ).find( '.wp-list-table' ).css( { - 'margin-top': 'initial', + $emailSelection.hide().closest( 'body' ).find( '.tablenav' ).css( { + 'height': 'initial', } ); } } ); - $( document ).on( 'change', '#wpo_bewc_email_selection select', function ( e ) { + $( document ).on( 'change', '.wpo_bewc_email_selection select', function ( e ) { e.preventDefault(); let email = $( this ).val(); - let selectors = $( this ).closest( 'body' ).find( '#wpo_bewc_email_selection select' ); + let selectors = $( this ).closest( 'body' ).find( '.wpo_bewc_email_selection select' ); $.each( selectors, function( i, selector ) { $( selector ).val( email ); @@ -34,7 +38,7 @@ jQuery( function( $ ) { } ).trigger( 'change' ); $( document ).on( 'submit', 'form#posts-filter, form#wc-orders-filter', function( e ) { - let emailSelectionEmpty = $( this ).find( '#wpo_bewc_email_selection select' ).val().length === 0; + let emailSelectionEmpty = $( this ).find( '.wpo_bewc_email_selection select' ).val().length === 0; let hasCheckedOrders = $( this ).find( '.wp-list-table .check-column input[type="checkbox"]:checked' ).length > 0; if ( $( this ).find( 'select[name="action"]' ).val() === 'wpo_bewc_send_email' ) { diff --git a/bulk-emails-for-woocommerce.php b/bulk-emails-for-woocommerce.php index a2bd13d..e1c4f40 100644 --- a/bulk-emails-for-woocommerce.php +++ b/bulk-emails-for-woocommerce.php @@ -90,7 +90,7 @@ public function bulk_actions( $actions ) { public function email_selector() { if ( ( isset( $_REQUEST['post_type'] ) && 'shop_order' == $_REQUEST['post_type'] ) || ( isset( $_REQUEST['page'] ) && 'wc-orders' == $_REQUEST['page'] ) ) { ?> -