Home / Admin / REST API Shopping Cart Endpoint for EDD
Duplicate Snippet

Embed Snippet on Your Site

REST API Shopping Cart Endpoint for EDD

Adds a REST API endpoint that returns the current user's shopping cart.

Code Preview
php
<?php
function totc_edd_rest_endpoints() {
	register_rest_route(
		'totc/1.0',
		'/edd/cart',
		array(
			'methods' => 'GET',
			'callback' => 'totc_edd_rest_cart',
		)
	);
}
add_action( 'rest_api_init', 'totc_edd_rest_endpoints' );
/**
 * Respond to requests to the cart REST endpoint
 *
 * @param $request WP_REST_Request
 */
function totc_edd_rest_cart( WP_REST_Request $request ) {
	return edd_get_cart_content_details();
}

Comments

Add a Comment