Exclude Suspended Vendors from Announcement Email
By default, clicking “select all” vendors for the announcement will include your suspended vendors as well. On my site, I suspended certain vendors for a reason, and did not feel it was appropriate to contact them with things like site updates during that time. So if you would like the default behavior to only include active vendors, simply add this code to your child theme’s functions.php file:
add_action('add_meta_boxes', 'wcmp_remove_meta_boxes',99);
function wcmp_remove_meta_boxes() {
remove_meta_box('wcmp_vendor_notice_select_vendor', 'wcmp_vendor_notice', 'side');
add_meta_box(
'wcmp_vendor_notice_select_vendor',
__( 'Vendors', 'dc-woocommerce-multi-vendor' ),
'wcmp_vendor_notice_select_vendor_callback',
'wcmp_vendor_notice',
'side',
'low'
);
}
function wcmp_vendor_notice_select_vendor_callback() {
global $post;
$selected_vendors = (array)get_post_meta( $post->ID, '_wcmp_vendor_notices_vendors', true );
wp_add_inline_script( 'wcmp_admin_js', '( function( $ ) {
$("#show_announcement_vendors").select2({
placeholder: "'.__('Select vendor...', 'dc-woocommerce-multi-vendor').'"
});
$("#anv_select_all").click(function(){
$("#show_announcement_vendors > option").prop("selected","selected");
$("#show_announcement_vendors").trigger("change");
});
$("#anv_reset").click(function(){
$("#show_announcement_vendors").val(null).trigger("change");
});
} )( jQuery );' );
?>
<div class="announcement-vendors-wrap">
<select id="show_announcement_vendors" name="show_announcement_vendors[]" class="" multiple="multiple" style="width:100%;">
<?php
$vendors = get_wcmp_vendors();
if ($vendors){
foreach ($vendors as $vendor) {
$is_suspended =get_user_meta( $vendor->id, '_vendor_turn_off', true);
if( !$is_suspended ){
$selected = in_array($vendor->id, $selected_vendors) ? 'selected' : '';
echo '<option value="' . esc_attr($vendor->id) . '" '.$selected.'>' . esc_html($vendor->page_title) . '</option>';
}
}
}
?>
</select>
<p>
<button type="button" class="button button-default" id="anv_select_all"><?php _e( 'Select All', 'dc-woocommerce-multi-vendor' ); ?></button>
<button type="button" class="button button-default" id="anv_reset"><?php _e( 'Reset', 'dc-woocommerce-multi-vendor' ); ?></button>
</p>
</div>
<?php
}
Tested and working on Woocommerce 4.6.1, WCMp 3.5.10
Is this no longer relevant or not working? Please let us know in the comments!