это и есть "полный url", откуда можно забрать картинку
add_action('init', function() {
function get_user_by_chat_id( WP_REST_Request $userChatId ){
$user = get_users(array('meta_key' => 'chatid', 'meta_value' => (int) $userChatId['id']));
if ( empty( $user ) )
return new WP_Error( 'no_users', 'User with this chat id not found', [ 'status' => 404 ] );
return $user;
}
});
add_action( 'rest_api_init', function(){
register_rest_route( 'wc/v3', 'customers?meta_data={"chatid":"(?P<id>\d+)"}', [
'methods' => 'GET',
'callback' => 'get_user_by_chat_id',
] );
} );
$(document).on('click', '.mini-increment', function (e){
var qty = $(this).prev().val();
var cart_item_key = $(this).prev().attr("id");
$.ajax({
type: 'POST',
dataType: 'json',
url: ajax_url,
data: {action : 'update_item_from_cart', 'cart_item_key' : cart_item_key, 'qty' : qty, },
success: function (data) {
if (data) {
console.log('Error');
}else{
console.log('Cart updated');
//$(document.body ).trigger( 'wc_fragment_refresh' )
}
}
});
});
function update_item_from_cart() {
$cart_item_key = $_POST['cart_item_key'];
$quantity = $_POST['qty'];
// Get mini cart
ob_start();
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item)
{
if( $cart_item_key == $_POST['cart_item_key'] )
{
WC()->cart->set_quantity( $cart_item_key, $quantity, $refresh_totals = true );
}
}
WC()->cart->calculate_totals();
WC()->cart->maybe_set_cart_cookies();
return true;
}
add_action('wp_ajax_update_item_from_cart', 'update_item_from_cart');
add_action('wp_ajax_nopriv_update_item_from_cart', 'update_item_from_cart');
Controller
Service