Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the email selector issues #9

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,43 @@ 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 );
} );
} ).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' ) {
Expand Down
2 changes: 1 addition & 1 deletion bulk-emails-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {
?>
<div id="wpo_bewc_email_selection" style="display:none;">
<div class="wpo_bewc_email_selection" style="display:none;">
<span>
<select name="wpo_bewc_email_select" style="width:200px; margin-right:6px;">
<option value=""><?php esc_html_e( 'Choose an email to send', 'bulk-emails-for-woocommerce' ); ?></option>
Expand Down
Loading