• Resolved ashop1

    (@ashop1)


    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);
    • This topic was modified 4 years, 11 months ago by Yui. Reason: formatting
Viewing 6 replies - 1 through 6 (of 6 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi @ashop1,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Thread Starter ashop1

    (@ashop1)

    Plugin Support Thu P. a11n

    (@thup90)

    Hi @ashop1,

    Did you try the solution in that thread you linked to?

    If that doesn’t work, I’d recommend what we suggested earlier for more development oriented channels.

    Thread Starter ashop1

    (@ashop1)

    I already answered in that thread, so we don’t mix the songs.

    on this thread, surely they mark it, as always, as solved although it is not like that.

    Since I provide a code that works but is missing perhaps a single word or a small line to make it work as I wish, showing the result only once, they could help me since it is also related exclusively to woocommerce. But you don’t do that, Mirko P. tells me that it is a fairly complex development, but the code is almost complete if I’m not mistaken, and I just showed it myself, if what is missing is minimal … where is the complexity that do not help?

    I understand that they will say something about their policies maybe, but if so then do not mark something that is not resolved as a result because it could confuse people who enter solved woocommerce threads when they did not help nor is that thread resolved.

    Plugin Support Thu P. a11n

    (@thup90)

    Hi @ashop1,

    Our support staff including myself are not developers though who could offer guidance on the API functionality as we only offer support for the default features and functionality of our products that do not require any custom code to function or integrate.

    Posting on more development oriented channels as listed above would be the best next step here for help with development topics.

    For customization, I can recommend reaching out to a developer locally or to someone from our customizations page https://woocommerce.com/customizations/

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘get data only once using foreach (WC () …’ is closed to new replies.