Home Forums WC Vendors Pro Support shipping cost going to admin

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #65319
    Jay Ryu
    Participant

    Hello, I believe someone raised this issue some time ago but it seems it has yet to be fixed. shipping costs are still going to admin, not to vendors.

    Thanks for the update!

    #65375
    Anna
    Member

    @elsa
    Jay,
    Is this for Variable products only, or all product types?
    If for variable, it is a known issue and we are working on a solution.
    If this is happening for more product types, let me know.

    #66018
    Robert Edilson
    Participant

    I’m having this issue as well. Thanks for working on a solution for this!

    #66036
    Anna
    Member

    @elsa @redilson
    Hello,
    If this is with variable products- I do believe this issue has finally been resolved, and the fix will be in our next WC Vendors Pro update.

    #66161
    DELETE
    Participant

    This only works if you use the WC Vendors Pro built-in shipping method. Not obvious at all, but you can also get it to work without using the WC Vendors shipping method.

    Reply if you’re interested and I’ll post some instructions on how to do this.

    #66166
    Garry Mitchell
    Participant

    @Avishai, I’d be very interested in knowing how you’ve managed to get shipping costs working with other shipping methods!

    #66170
    DELETE
    Participant

    @105EOC the way I was able to accomplish this is by hooking into the woocommerce_order_status_processing action. This event is triggered once an order payment is complete, which in effect means that when someone submits the credit card payment, the action is triggered. The following code catches the order, and then loops through the shipping line items associated with it. Based on the product ids, it finds the vendor, and writes a “commission” line item to the WC Vendors commission table.

    Important note: You must configure your WooCommerce to group the shopping cart into multiple “shipping packages” by vendor/product owner id. I’m using this: https://github.com/academe/wc-multiple-packages. If you skip this step, the values calculated by the below code will likely be wrong.

    
    // Give vendors any shipping costs collected from the customer
    function give_vendor_shipping_cost( $order_id, $vendor_id, $shipping_cost, $shipping_tax ) {
    	global $wpdb;
    	$insert_query   = "INSERT INTO 'wp_pv_commission' ('order_id', 'vendor_id', 'qty', 'total_shipping', 'tax', 'status', 'time') VALUES (%d, %d, %d, %f, %f, %s, %s)";
    	$results = $wpdb->get_results( $wpdb->prepare( $insert_query,
    		$order_id,
    		$vendor_id,
    		0, // qty always 0 for a shipping line item, since it's not really relevant as it's a sum of total shipping
    		$shipping_cost,// total shipping
    		$shipping_tax,// total tax on shipping
    		"due", // finally, the status. need to be "due"
    		current_time('mysql', false)
    	) );
    }
    
    add_action( 'woocommerce_order_status_processing', 'give_shipping_costs_to_vendors' );
    function give_shipping_costs_to_vendors( $order_id ) {
    	// TODO: add error checking to make sure that vendor doesn't get paid
    	// shipping twice or more for the same order
    	$order = new WC_Order( $order_id );
    	error_log("Adding shipping costs to commission table");
    	$shipping_line_items = $order->get_items( 'shipping' );
    	foreach ($shipping_line_items as $shipping) {
    		$shipping_cost = array_sum($shipping['item_meta']['cost']);
    		$shipping_tax = 0.0;
    		$shipping_tax_costs = unserialize($shipping['item_meta']['taxes'][0]);
    		foreach ($shipping_tax_costs as $rate_id => $value) {
    			$shipping_tax += floatval($value);
    		}
    		$product_ids = $shipping['item_meta']['_product_ids'];
    		// error_log(print_r($product_ids, true));
    		// in theory, we should make sure that there isn't more than one post_author regardless of the number of produts
    		// in practice, cart is grouped by vendor id anyhow, so any product_id associated with a shipping line
    		// should already be from the same vendor id
    		$vendor_id = get_post_field( 'post_author', reset($product_ids) ); // reset() gets first element
    		// error_log($vendor_id);
    		// TODO: get vendor_id from split($pduct)
    		give_vendor_shipping_cost( $order_id, $vendor_id, $shipping_cost, $shipping_tax );
    	}
    	return $order_id; // seems kinda pointless, but whatever
    }
    
    #66191
    Garry Mitchell
    Participant

    Thank you very much, I shall give this a try!

    #66324
    Arnaud
    Participant

    @avishai the solution you bring look like a great hope for me to solve the biggest (and unsolvable for me) problem I have with wc vendors pro.

    I tried to insert your code in my functions.php file after installing et setting up wc-multiple-packages (group by vendor). This give me a blank screen that I failed to debug after several tests.

    I have a good knowledge of WordPress and Woocommerce, but I’m not a seasoned developer.

    Could you guide me with further explanations on how to proceed to let your code be operational ?

    Thank you in advance.

    #66334
    Arnaud
    Participant

    @avishai Could you give further explanations on how to proceed to let your code be operational ?

    I tried to insert your code in my functions.php file after installing et setting up wc-multiple-packages (group by vendor). This give me a blank screen that I failed to debug after several tests.

    Thanks in advance !

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.
This website uses cookies to ensure you get the best experience on our website.