Предполагая, что ваши WordPress и Laravel находятся в одном домене, вы можете сделать ajax-вызов в бэкэнд WordPress, чтобы получить данные корзины.
jQuery, чтобы сделать ajax-вызов
(function ($) {
$( document ).ready(function() {
$.ajax ({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
dataType: 'JSON',
success: function (resp) {
if (resp.success) {
// build your cart details
}
else {
// handle the error
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert ('Request failed: ' + thrownError.message) ;
},
}) ;
}) ;
})(jQuery) ;
В вашей теме functions.php
файл зарегистрируйте вызов ajax
<?php
// if the ajax call will be made from JS executed when user is logged into WP
add_action ('wp_ajax_call_your_function', 'get_woocommerce_cart_data') ;
// if the ajax call will be made from JS executed when no user is logged into WP
add_action ('wp_ajax_nopriv_call_your_function', 'get_woocommerce_cart_data') ;
function get_woocommerce_cart_data () {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
// build the output array
$out = array();
foreach($items as $item => $values) {
// get product details
$getProductDetail = wc_get_product( $values['product_id'] );
$out[$item]['img'] = $getProductDetail->get_image();
$out[$item]['title'] = $getProductDetail->get_title();
$out[$item]['quantity'] = $values['quantity'];
$out[$item]['price'] = get_post_meta($values['product_id'] , '_price', true);
}
// retun the json
wp_send_json_success($out);
}