I've got a function hooked into load-edit.php that prints out print content:
add_action('load-edit.php', array($this, 'generate_bulk_print_content'));
public function generate_bulk_print_content() {
//check for bulk action & print
}
I prepared the bulk action trigger with the following (common) hack:
add_action( 'admin_footer-edit.php', array(&$this, 'add_to_bulk_actions'));
public function add_to_bulk_actions() {
global $post_type;
if ( 'shop_order' == $post_type ) {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('<option>').val('custact').text('<?php _e( 'Custom action', 'woocommerce' )?>').appendTo("select[name='action']");
jQuery('<option>').val('custact').text('<?php _e( 'Custom action', 'woocommerce' )?>').appendTo("select[name='action2']");
});
</script>
<?php
}
}
all of this works like one would expect, except for the fact that I can only see my print content when I do die() or exit() after the content. However, I would like this print content to be displayed in a thickbox on the admin page rather than on a new (otherwise empty) page. When I try to access the action variables in a different location, it cannot access the action variables anymore. What's happening in between my click on the action button and the next moment when I'm on the edit page again? Where does my print content go?
Are there other ways to use the existing buttons and perhaps get my stuff into admin-ajax rather than the edit page (which is a full reload I think)?
edit: got a bit further, I realised I probably shouldn't use the default action of reloading the page when the button is clicked, and now I'm using the following JS:
$("#doaction, #doaction2").click(function (event) {
var actionselected = $(this).attr("id").substr(2);
if ($('select[name="' + actionselected + '"]').val() == "bulkprint") {
event.preventDefault();
var checked = [];
$('tbody th.check-column input[type="checkbox"]:checked').each(
function() {
checked.push($(this).val());
}
);
data = {
action: 'bulkprint',
orders: checked
};
$.post(ajaxurl, data, function (response) {
//how to output this to the standard thickbox?
});
}
});
Now the last piece of the puzzle is to get my ajax response into a thickbox. tb_show is not going to work because that requires a regular link, whereas I would like to pass post data to the admin-ajax (instead of using arguments).
<script>
? And whatthickbox
is this? ::: Bulk actions do refresh the page. What does Ajax has to do with this? ::: Maybe some screenshots would be useful, and a bit more of code to give an idea of what's going on. ::: Is your problem like this?