Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
During testing I'm creating lots of carts and orders with the one user. I'm using commerce_cart_order_load($user->uid) from within hook_commerce_checkout_page_info_alter() but it's consistently returning an old (the user's first?) cart rather than the current / most recent cart for that user.
I'm using commerce_nocart to provide direct checkout for event registrations, so not sure this makes a difference.
How do programmatically get the user's current order (specifically the current order total) from within hook_commerce_checkout_page_info_alter() ?
Comments
Comment #2
czigor CreditAttribution: czigor at Centarro for FREITAG lab. AG commentedcommerce_cart_order_load() should be working fine for this purpose. What does it return when running it in devel/php?
Comment #3
inteja CreditAttribution: inteja commentedIt returns an old (that user's first) abandoned cart, not the most recent. When I delete that cart and subsequently test, it returns the 2nd abandoned cart for that user, not the most recent/current.
Comment #4
jsacksick CreditAttribution: jsacksick at Centarro commented@inteja:
For logged in users, the one with the highest order_id should be returned first.
Could you check if you don't have a module that implements the
hook_commerce_cart_order_id()
? That could be the explanation.Comment #5
inteja CreditAttribution: inteja commentedLooks like commerce_nocart implements hook_commerce_order_id() :
Comment #6
rszrama CreditAttribution: rszrama at Centarro commented