From ae30cca6176e04d429aaece008bf6c0c5b3c5c73 Mon Sep 17 00:00:00 2001 From: Mohamad Nateqi Rostami Date: Thu, 23 Jan 2025 13:15:13 +0330 Subject: [PATCH 1/3] Fix the email selector issues --- assets/js/scripts.js | 33 +++++++++++++++++++-------------- bulk-emails-for-woocommerce.php | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/assets/js/scripts.js b/assets/js/scripts.js index f919331..9c611bc 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -5,28 +5,33 @@ jQuery( function( $ ) { let actionSelected = $( this ).val(); if ( 'wpo_bewc_send_email' === actionSelected ) { - $( '#wpo_bewc_email_selection' ) + // Move the element to the correct location if it's not. + if ( ! $( '.wpo_bewc_email_selection' ).parent().is( '.tablenav' ) ) { + $( '.wpo_bewc_email_selection' ) + .insertAfter( '#wpbody-content .tablenav-pages' ) + .css( { + 'display': 'block', + 'clear': 'left', + 'padding-top': '6px', + } ); + } + + $( '.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', + .closest( 'body' ).find( '.tablenav' ).css( { + 'height': 'auto', } ); } else { - $( '#wpo_bewc_email_selection' ).hide().closest( 'body' ).find( '.wp-list-table' ).css( { - 'margin-top': 'initial', + $( '.wpo_bewc_email_selection' ).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 +39,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'] ) ) { ?> -