woocommerce payfast split payment to merchant id based on product purchased?

165 Views Asked by At

based off this link Payfast split payments which appears to work. How does one run a multi vendor woocommerce store and then split the payment to the associated merchant based on the product purchased?

1

There are 1 best solutions below

0
On

Typically, this information is stored at the order item level. So, you need to loop through the items, get the vendor id and do your splitting payment action. E.g. like this on the admin order page:

global $order;
$items = $order->get_items();
foreach ( $items as $item_key => $item ) {
    $vendor_id = wc_get_order_item_meta(  $item_key,  '_vendor_id', true );
    // Now get the merchant id with $vendor_id (=user id) and do split payment. 
    // You can also create an array with $merchant_id => $item->get_subtotal() 
    // and do the split payment after the loop.
}

The meta key "_vendor_id" depends on your plugin - I used WCMP (Multivendor Marketplace Solution for WooCommerce – WC Marketplace). You may need to look it up in your database how the field is called.