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 I show a fragment to which you should modify something so that the result is only shown once and not every time a product is added:
add_action('antes_titulo_carrito454', '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="titulo-carrito">Estás comprando en la tienda: ';echo'<div id="sdds">'.$store_name.'';
} };
source https://stackoverflow.com/questions/68145465/get-data-only-once-using-foreach-wc
Comments
Post a Comment