get information about the first post added to the woocommerce cart
-
First of all, apologies for writing here, is that in woocommerce they do not respond to more than generic messages.
hello, I have a query that I think should be straightforward for someone who has already implemented it. For me to solve this is not it since I have been all day but I can not:
I have this code to show on my cart page a title that indicates the name of the author of the publication that the user added (I clarify that I have restricted to add publications or products of more than one user so the title works very well highlighting the name of the author or the seller).
add_action (‘cart_title454’, ‘dcms_question_whatsap145p’);
function dcms_question_whatsap145p () {
foreach (WC () -> cart-> get_cart () as $ cart_item_key => $ cart_item) {$ product_id = $ cart_item [‘product_id’]; // Product ID
$ vendor_id = get_post_field (‘post_author’, $ product_id);$ store_user = wcfmmp_get_store ($ vendor_id);
$ store_name = $ store_user-> get_shop_name ();
echo ‘<div class = “cart-title”> You are shopping at the store:’; echo ‘<div id = “sdds”>’. $ store_name. ”;
}
};The problem is that my code shows me the same echo or result, that is, the same title for each publication or product that is added, and this should not be the case, it should only be shown once. I understand that this happens because the beginning of my code in the foreach line is obtaining, if I do not understand correctly, the entire cart in its entirety. So I need to correct that code, if possible, to only get the first article or the first post that the user (customer) adds to the cart page.
Is there any clue on how to correct that foreach line to make the rest work?
Thank you so much
- The topic ‘get information about the first post added to the woocommerce cart’ is closed to new replies.