Can I have cart id after calling WC()->cart->add_to_cart( ) method?
-
Hello,
I have developed a WordPress plugin which adds WooCommerce products programmatically using this code:
WC()->cart->empty_cart();
foreach ($productos as $producto) {
WC()->cart->add_to_cart($producto->post_id, $cantidad);
}After I add products to cart I need to save the cart id, because after the user proceeded to checkout and did the payment, I need to save the order id in a custom database table. I need cart id because when the order is processed, I need to match it to a record in that custom database table.
For example, if my custom database table, called wp_mycustom, has these records:
ID Name cart_id order_id
1 One Record —- —–
2 Other Record 12345 <—- This is the record that is associated with certain purchaseSo, when the order is completed, I need to update the record whose ID is 2 with the corresponding order ID generated when completed.
How can I accomplish that?
Thanks
Jaime
- The topic ‘Can I have cart id after calling WC()->cart->add_to_cart( ) method?’ is closed to new replies.