moderncaliber
Forum Replies Created
-
Forum: Plugins
In reply to: [Headless WooCommerce Made Easy with CoCart] Product Not DeletingJWT Authentication for the WordPress REST API. So I’m storing a token and then authenticating with that. Here is my code. But for now I have switched to only using CoCart for adding products to the cart, and redirecting to the WooCommerce cart itself instead of building a cart with NextJS and CoCart
// Set up the Authorization header with the Bearer token
const config = {
headers: { Authorization:Bearer ${token}
},
}
const response = await axios.delete(
${process.env.NEXT_PUBLIC_URL}/wp-json/cocart/v2/cart/item/${itemKey}
,
config
)Forum: Plugins
In reply to: [Enable CORS] API Request has been blocked by CORS policyI have another idea. It appears every time I get this error, it is also paired with this one. https://shirksllc.net/wp-json/jwt-auth/v1/token/validate net::ERR_FAILED 429 (Too Many Requests)
Could that mean it is a separate wordpress issue I need to resolve with someone else?
Forum: Plugins
In reply to: [Enable CORS] API Request has been blocked by CORS policyThat all sounds great but I’m not too experienced with CORS stuff so could you give me some more specific steps? I’ll try to give you some more context too.
Sometimes the CORS works and sometimes it doesn’t. So for example my cart fetch is authenticated. Sometimes the CORS headers are there and it fetches correctly. And other times it says I’m missing a CORS header. So it’s not consistent.
I also added this code below to my theme’s functions.php
function add_cors_http_header(){
header(“Access-Control-Allow-Origin: *”);
}
add_action(‘init’,’add_cors_http_header’);Ok so the way I have it is the best way then? It currently sends them to the cart. If they aren’t logged in, they log in and it shows them their cart that they can checkout from.
so what is the recommended way to get to checkout from cocart?
Ok so I figured out some things. So I actually wanted to authenticating my requests to cocart so the products are getting added to the user’s cart instead of a guest cart made with a cart key. But that brings up another problem. If I add products to the user’s cart from my front end (shirksllc.com) and then go to the woocommerce cart / checkout (shirksllc.net/cart or shirksllc.net/checkout), the user isn’t authenticated on the wordpress side so it says my cart is empty. Is there a way to authenticate the user on wordpress from cocart?
Ok I see what you’re asking. So I just tried some things and here is what is happening. My custom build front end is at shirksllc.com. My wordpress backend is at shirksllc.net. My front end is using the cart key to populate the cart. When I load the cart session it takes me to the woocommerce checkout at shirksllc.net. When I check out, the cart at shirksllc.net clears, but the cart attached to the cart key on my front end doesn’t clear. So it cleared it on woocommerce, but it doesn’t clear the cart on my front end that uses cocart. Does that help?
I use Authorize.net. That is the only one I’m able to use because it is the one my client uses.
- Classic checkout I believe
- I was actually in an older version (4.1.0). I just upgraded to 4.2.0 and still had the same issue