/** * * * @param unknown $order_id * @param unknown $product * @param unknown $author * * @return unknown */ public static function get_shipping_due($order_id, $product, $author) { global $woocommerce; $shipping_costs = array('amount' => 0, 'tax' => 0); $shipping_due = 0; $method = ''; $_product = get_product($product['product_id']); $order = wc_get_order($order_id); if ($_product && $_product->needs_shipping() && !$_product->is_downloadable()) { // Get Shipping methods. $shipping_methods = $order->get_shipping_methods(); // TODO: Currently this only allows one shipping method per order, this definitely needs changing foreach ($shipping_methods as $shipping_method) { $method = $shipping_method['method_id']; break; } // Table Rate Shipping 2 if (strstr($method, 'table_rate') !== false) { // $shipping_due = WCV_Shipping::trs2_get_due( $order_id, $product[ 'product_id' ] ); // Per Product Shipping 2 } else { if ((class_exists('WC_Shipping_Per_Product_Init') || function_exists('woocommerce_per_product_shipping')) && $method == 'per_product') { $shipping_costs = WCV_Shipping::pps_get_due($order_id, $product); // Local Delivery } else { if ($method == 'local_delivery') { $local_delivery = get_option('woocommerce_local_delivery_settings'); if ($local_delivery['type'] == 'product') { $shipping_costs['amount'] = $product['qty'] * $local_delivery['fee']; $shipping_costs['tax'] = WCV_Shipping::calculate_shipping_tax($shipping_costs['amount'], $order); } // International Delivery } else { if ($method == 'international_delivery') { $int_delivery = get_option('woocommerce_international_delivery_settings'); if ($int_delivery['type'] == 'item') { $WC_Shipping_International_Delivery = new WC_Shipping_International_Delivery(); $fee = $WC_Shipping_International_Delivery->get_fee($int_delivery['fee'], $_product->get_price()); $shipping_costs['amount'] = ($int_delivery['cost'] + $fee) * $product['qty']; $shipping_costs['tax'] = 'taxable' === $int_delivery['tax_status'] ? WCV_Shipping::calculate_shipping_tax($shipping_costs['amount'], $order) : 0; } } } } } } $shipping_costs = apply_filters('wcvendors_shipping_due', $shipping_costs, $order_id, $product); return $shipping_costs; }
/** * * * @param unknown $order_id * @param unknown $product * @param unknown $author * * @return unknown */ public function get_shipping_due($order_id, $product, $author) { global $woocommerce; $shipping_due = 0; $_product = get_product($product['product_id']); if ($_product && $_product->needs_shipping()) { $order = new WC_Order($order_id); // Table Rate Shipping 2 if (strstr($order->shipping_method, 'table_rate') !== false) { // $shipping_due = PV_Shipping::trs2_get_due( $order_id, $product[ 'product_id' ] ); // Per Product Shipping 2 } else { if (function_exists('woocommerce_per_product_shipping') && $order->shipping_method == 'per_product') { $shipping_due = PV_Shipping::pps_get_due($order_id, $product); // Local Delivery } else { if ($order->shipping_method == 'local_delivery') { $local_delivery = get_option('woocommerce_local_delivery_settings'); if ($local_delivery['type'] == 'product') { $shipping_due = $product['qty'] * $local_delivery['fee']; } // International Delivery } else { if ($order->shipping_method == 'international_delivery') { $int_delivery = get_option('woocommerce_international_delivery_settings'); if ($int_delivery['type'] == 'item') { $WC_Shipping_International_Delivery = new WC_Shipping_International_Delivery(); $fee = $WC_Shipping_International_Delivery->get_fee($int_delivery['fee'], $_product->get_price()); $shipping_due = ($int_delivery['cost'] + $fee) * $product['qty']; } } } } } } $shipping_due = apply_filters('wc_product_vendor_shipping_due', $shipping_due, $order_id, $product); // Save the shipping due as a meta for the order if (!empty($shipping_due)) { $prev_shipping_due = (array) get_post_meta($order_id, '_vendor_shipping_due', true); $prev_shipping_due[$author] = !empty($prev_shipping_due[$author]) ? $prev_shipping_due[$author] + $shipping_due : $shipping_due; update_post_meta($order_id, '_vendor_shipping_due', array_filter($prev_shipping_due)); } return $shipping_due; }
/** * Get Vendor Shipping commission total. Supports Flat Rate, International Delivery and Local Delivery * * @param int $order_id * @param object $product */ public function get_wcmp_vendor_shipping_total($order_id, $product) { global $WCMp, $woocommerce; $vendor_shipping_costs = array('shipping_amount' => 0, 'shipping_tax' => 0); $method = ''; $_product = get_product($product['product_id']); $order = wc_get_order($order_id); if ($_product && $_product->needs_shipping() && !$_product->is_downloadable()) { $shipping_methods = $order->get_shipping_methods(); foreach ($shipping_methods as $shipping_method) { $method = $shipping_method['method_id']; break; } if ($method == 'flat_rate') { $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings'); if (version_compare(WC_VERSION, '2.4.0', '>')) { if ($woocommerce_flat_rate_settings['type'] == 'class') { $vendor_shipping_costs['shipping_amount'] = isset($product['flat_shipping_per_item']) ? $product['flat_shipping_per_item'] : ''; } } else { if ($woocommerce_flat_rate_settings['type'] == 'item') { $vendor_shipping_costs['shipping_amount'] = $product['flat_shipping_per_item']; } } } else { if ($method == 'local_delivery') { $local_delivery = get_option('woocommerce_local_delivery_settings'); if ($local_delivery['type'] == 'product') { $vendor_shipping_costs['shipping_amount'] = $product['qty'] * $local_delivery['fee']; $vendor_shipping_costs['shipping_tax'] = $this->calculate_shipping_tax($vendor_shipping_costs['shipping_amount'], $order); } // International Delivery } else { if ($method == 'international_delivery') { $wc_international_delivery = get_option('woocommerce_international_delivery_settings'); if (version_compare(WC_VERSION, '2.4.0', '>')) { if ($wc_international_delivery['type'] == 'class') { $vendor_shipping_costs['shipping_amount'] = isset($product['international_flat_shipping_per_item']) ? $product['international_flat_shipping_per_item'] : ''; } } else { if ($wc_international_delivery['type'] == 'item') { $WC_Shipping_International_Delivery = new WC_Shipping_International_Delivery(); $fee = $WC_Shipping_International_Delivery->get_fee($int_delivery['fee'], $_product->get_price()); $vendor_shipping_costs['shipping_amount'] = ($int_delivery['cost'] + $fee) * $product['qty']; $vendor_shipping_costs['shipping_tax'] = 'taxable' === $int_delivery['tax_status'] ? $this->calculate_shipping_tax($vendor_shipping_costs['shipping_amount'], $order) : 0; } } } } } } $vendor_shipping_costs = apply_filters('wcmp_vendors_shipping_amount', $vendor_shipping_costs, $order_id, $product); return $vendor_shipping_costs; }