вот так связать. Тут добавление товаров в корзину
$("a.button_close.filter_reset, .load_all_products").on("click", function () {
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
dataType: "html",
data: {
action : 'get_all_products',
},
success: function( data ) {
$(".select-hidden").each(function () {
$(this).parent().find(".select-styled").text($(this).parent().find(".select-options li:first-child").text());
$(this).removeClass("error_select");
});
$(".load_all_products").hide();
$( '.prods_row' ).html( data );
}
});
})
function get_all_products() {
// Query Arguments
$args = array(
'post_type' => array('product'),
'post_status' => array('publish'),
'orderby' => 'meta_value_num',
'meta_key' => '_price',
'order' => "DESC"
);
// The Query
$ajaxposts = new WP_Query( $args );
$response = '';
// The Query
if ( $ajaxposts->have_posts() ) {
while ( $ajaxposts->have_posts() ) {
$ajaxposts->the_post();
$response .= get_template_part('product_template');
}
} else {
$response .= get_template_part('none');
}
echo $response;
exit; // leave ajax call
}
// Fire AJAX action for both logged in and non-logged in users
add_action('wp_ajax_get_all_products', 'get_all_products');
add_action('wp_ajax_nopriv_get_all_products', 'get_all_products');