On the WordPress website where WooCommerce is running, a user can log in to their (by default) personal area and display information, for example:
- Order history
- Download
- Address
- Change information
- Exit
On the orders tab, a table is displayed by default showing a list of all orders, with a View button that redirects to the full details page of this order.
What I'm trying to do is show this table view in a modal window.
I have no problem showing the modal file with the destination URL loaded into it. The real problem is that the destination URL is a full page that displays as in an <iframe> , and that is not what I want.
I think there is a short code that allows you to load only this table, or maybe some woocommerce function, for example load_order_content_by_id($id) ?
Can someone point me in the right direction?
thanks
=== solvable ===
Thanks to Raunak Gupta for pointing me to the correct function. I redefined the orders.php template, added the Modal window html and edited the $actions :
'view' => array( 'url' => 'javascript:;', 'data' => [ 'order-number' => $order->get_order_number() ], 'name' => __( 'View', 'woocommerce' ) ),
and in the same file:
foreach ( $actions as $key => $action ) { echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '"'; if(isset($action['data']) && is_array($action['data'])){ foreach($action['data'] AS $data_attr=>$data_value){ echo 'data-' . sanitize_html_class($data_attr) .'="' .esc_html($data_value) . '" '; } } echo '>' . esc_html( $action['name'] ) . '</a>'; }
Little js
$('.woocommerce-MyAccount-orders .button.view').on('click', function(e){ e.preventDefault(); var data = {}; data.action = 'modal_order'; data.order_number = $(this).data('order-number'); $.get( ajax_script.ajax_url, data, function(response) { $('#modalOrderDetail').modal('show').find('.modal-body').html(response); }); });
and caught on wordpress function.php
function modal_order() { if(is_user_logged_in()) { $order_number = $_GET['order_number']; woocommerce_order_details_table($order_number); } } add_action('wp_ajax_modal_order', 'modal_order'); add_action('wp_ajax_nopriv_modal_order', 'modal_order');