• hi, i have some code snippets to get seller data in woocommerce cart, but i have a problem because the same information is repeated every time a new product is added to the cart.

    Apparently logic obtains the information based on the added product and repeats it for each product. Is there any way to modify or add something in the fragment so that it only gets the information of the first product and therefore only shows the obtained data once or something like that for this purpose?

    here my fragments:

    add_action ('cart_title454', 'dcms_question_whatsap1405p');
    function dcms_question_whatsap1405p () {
    foreach (WC () -> cart-> get_cart () as $ cart_item_key => $ cart_item) {
    
    $ vendor_id = $ cart_item ['data'] -> post-> post_author;
    
      
    echo '<div class = "cart-title"> You are shopping at the store:'; echo '<div id = "sdds">'. $ vendor_id. '';
    }
    };
    
    add_action ('before_carrito_title454', 'woo_add_continue_shopping_button_to_cart'); function woo_add_continue_shopping_button_to_cart () {
    
    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_url = wcfmmp_get_store_url ($ vendor_id); ; echo '<a href="'.$store_url.'"> Continue shopping </a>';}}
    
    add_action ('before_cart_title454', function () {
    foreach (WC () -> cart-> get_cart () as $ cart_item_key => $ cart_item) {
    $ _product = apply_filters ('woocommerce_cart_item_product', $ cart_item ['data'], $ cart_item, $ cart_item_key);
    $ vendor_id = wcfm_get_vendor_id_by_post ($ _product-> get_id ());
    $ store_user = wcfmmp_get_store ($ vendor_id);
    $ store_name_title = $ store_user-> get_shop_name ();
    $ vendor_data = get_user_meta ($ vendor_id, 'wcfmmp_profile_settings', true);
    $ all_bank_detailts = $ vendor_data ['payment'] ['bank'];
    
    echo 'CBU from'. $ store_name_title. ':'. $ all_bank_detailts ['ac_number'];
    
    }
    }, 30);
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get data only once using foreach (WC () -> cart->…’ is closed to new replies.