/** * * * @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; }
/** * Shipping and taxes */ public function wc_setup_shipping_taxes() { $domestic = new WC_Shipping_Flat_Rate(); $international = new WC_Shipping_International_Delivery(); $shipping_cost_domestic = ''; $shipping_cost_international = ''; if ('yes' === $domestic->get_option('enabled')) { $shipping_cost_domestic = $domestic->get_option('cost'); } if ('yes' === $international->get_option('enabled')) { $shipping_cost_international = $international->get_option('cost'); } ?> <h1><?php _e('Shipping & Tax Setup', 'woocommerce'); ?> </h1> <form method="post"> <p><?php printf(__('If you will be charging sales tax, or shipping physical goods to customers, you can configure the basic options below. This is optional and can be changed later via %1$sWooCommerce > Settings > Tax%3$s and %2$sWooCommerce > Settings > Shipping%3$s.', 'woocommerce'), '<a href="' . admin_url('admin.php?page=wc-settings&tab=tax') . '" target="_blank">', '<a href="' . admin_url('admin.php?page=wc-settings&tab=shipping') . '" target="_blank">', '</a>'); ?> </p> <table class="form-table"> <tr class="section_title"> <td colspan="2"> <h2><?php _e('Basic Shipping Setup', 'woocommerce'); ?> </h2> </td> </tr> <tr> <th scope="row"><label for="woocommerce_calc_shipping"><?php _e('Will you be shipping products?', 'woocommerce'); ?> </label></th> <td> <input type="checkbox" id="woocommerce_calc_shipping" <?php checked(get_option('woocommerce_calc_shipping', 'no'), 'yes'); ?> name="woocommerce_calc_shipping" class="input-checkbox" value="1" /> <label for="woocommerce_calc_shipping"><?php _e('Yes, I will be shipping physical goods to customers', 'woocommerce'); ?> </label> </td> </tr> <tr> <th scope="row"><label for="shipping_cost_domestic"><?php _e('<strong>Domestic</strong> shipping costs:', 'woocommerce'); ?> </label></th> <td> <?php printf(__('A total of %s per order and/or %s per item', 'woocommerce'), get_woocommerce_currency_symbol() . ' <input type="text" id="shipping_cost_domestic" name="shipping_cost_domestic" size="5" value="' . esc_attr($shipping_cost_domestic) . '" />', get_woocommerce_currency_symbol() . ' <input type="text" id="shipping_cost_domestic_item" name="shipping_cost_domestic_item" size="5" />'); ?> </td> </tr> <tr> <th scope="row"><label for="shipping_cost_international"><?php _e('<strong>International</strong> shipping costs:', 'woocommerce'); ?> </label></th> <td> <?php printf(__('A total of %s per order and/or %s per item', 'woocommerce'), get_woocommerce_currency_symbol() . ' <input type="text" id="shipping_cost_international" name="shipping_cost_international" size="5" value="' . esc_attr($shipping_cost_international) . '" />', get_woocommerce_currency_symbol() . ' <input type="text" id="shipping_cost_international_item" name="shipping_cost_international_item" size="5" />'); ?> </td> </tr> <tr class="section_title"> <td colspan="2"> <h2><?php _e('Basic Tax Setup', 'woocommerce'); ?> </h2> </td> </tr> <tr> <th scope="row"><label for="woocommerce_calc_taxes"><?php _e('Will you be charging sales tax?', 'woocommerce'); ?> </label></th> <td> <input type="checkbox" <?php checked(get_option('woocommerce_calc_taxes', 'no'), 'yes'); ?> id="woocommerce_calc_taxes" name="woocommerce_calc_taxes" class="input-checkbox" value="1" /> <label for="woocommerce_calc_taxes"><?php _e('Yes, I will be charging sales tax', 'woocommerce'); ?> </label> </td> </tr> <tr> <th scope="row"><label for="woocommerce_prices_include_tax"><?php _e('How will you enter product prices?', 'woocommerce'); ?> </label></th> <td> <label><input type="radio" <?php checked(get_option('woocommerce_prices_include_tax', 'no'), 'yes'); ?> id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="yes" /> <?php _e('I will enter prices inclusive of tax', 'woocommerce'); ?> </label><br/> <label><input type="radio" <?php checked(get_option('woocommerce_prices_include_tax', 'no'), 'no'); ?> id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="no" /> <?php _e('I will enter prices exclusive of tax', 'woocommerce'); ?> </label> </td> </tr> <?php $locale_info = (include WC()->plugin_path() . '/i18n/locale-info.php'); $tax_rates = array(); $country = WC()->countries->get_base_country(); $state = WC()->countries->get_base_state(); if (isset($locale_info[$country])) { if (isset($locale_info[$country]['tax_rates'][$state])) { $tax_rates = $locale_info[$country]['tax_rates'][$state]; } elseif (isset($locale_info[$country]['tax_rates'][''])) { $tax_rates = $locale_info[$country]['tax_rates']['']; } if (isset($locale_info[$country]['tax_rates']['*'])) { $tax_rates = array_merge($locale_info[$country]['tax_rates']['*'], $tax_rates); } } if ($tax_rates) { ?> <tr> <th scope="row"><label for="woocommerce_import_tax_rates"><?php _e('Import Tax Rates?', 'woocommerce'); ?> </label></th> <td> <label><input type="checkbox" id="woocommerce_import_tax_rates" name="woocommerce_import_tax_rates" class="input-checkbox" value="yes" /> <?php _e('Yes, please import some starter tax rates', 'woocommerce'); ?> </label> <div class="importing-tax-rates"> <table class="tax-rates"> <thead> <tr> <th><?php _e('Country', 'woocommerce'); ?> </th> <th><?php _e('State', 'woocommerce'); ?> </th> <th><?php _e('Rate (%)', 'woocommerce'); ?> </th> <th><?php _e('Name', 'woocommerce'); ?> </th> <th><?php _e('Tax Shipping', 'woocommerce'); ?> </th> </tr> </thead> <tbody> <?php foreach ($tax_rates as $rate) { ?> <tr> <td><?php echo esc_attr($rate['country']); ?> </td> <td><?php echo esc_attr($rate['state'] ? $rate['state'] : '*'); ?> </td> <td><?php echo esc_attr($rate['rate']); ?> </td> <td><?php echo esc_attr($rate['name']); ?> </td> <td><?php echo empty($rate['shipping']) ? '-' : '✔'; ?> </td> </tr> <?php } ?> </tbody> </table> <p class="description"><?php _e('Please note: you may still need to add local and product specific tax rates depending on your business location. If in doubt, speak to an accountant.', 'woocommerce'); ?> </p> </div> <p class="description"><?php printf(__('You can edit tax rates later from the %1$stax settings%3$s screen and read more about taxes in %2$sour documentation%3$s.', 'woocommerce'), '<a href="' . admin_url('admin.php?page=wc-settings&tab=tax') . '" target="_blank">', '<a href="http://docs.woothemes.com/document/setting-up-taxes-in-woocommerce/" target="_blank">', '</a>'); ?> </p> </td> </tr> <?php } ?> </table> <p class="wc-setup-actions step"> <input type="submit" class="button-primary button button-large" value="<?php esc_attr_e('Continue', 'woocommerce'); ?> " name="save_step" /> <a href="<?php echo esc_url($this->get_next_step_link()); ?> " class="button button-large"><?php _e('Skip this step', 'woocommerce'); ?> </a> <?php wp_nonce_field('wc-setup'); ?> </p> </form> <?php }
/** * WCMp Calculate shipping for order * * @support flat rate per item * @param int $order_id * @param object $order_posted * @return void */ function wcmp_checkout_order_processed($order_id, $order_posted) { global $wpdb, $WCMp; $order = new WC_Order($order_id); if ($order->has_shipping_method('flat_rate')) { $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings'); $line_items = $order->get_items('line_item'); if ($woocommerce_flat_rate_settings['enabled'] == 'yes') { if (version_compare(WC_VERSION, '2.5.0', '>=')) { if ($woocommerce_flat_rate_settings['type'] == 'class') { if (!empty($line_items)) { foreach ($line_items as $item_id => $item) { $wc_flat_rate = new WC_Shipping_Flat_Rate(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class_id(); $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true); if (!$flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2)); } } } } } else { if (version_compare(WC_VERSION, '2.4.0', '>')) { if ($woocommerce_flat_rate_settings['type'] == 'class') { if (!empty($line_items)) { foreach ($line_items as $item_id => $item) { $wc_flat_rate = new WC_Shipping_Flat_Rate(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class(); $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true); if (!$flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2)); } } } } } else { $woocommerce_flat_rate_settings_cost = $woocommerce_flat_rate_settings['cost']; $woocommerce_flat_rate_settings_fee = $woocommerce_flat_rate_settings['fee']; $woocommerce_flat_rates = get_option('woocommerce_flat_rates'); if ($woocommerce_flat_rate_settings['type'] == 'item') { if (!empty($line_items)) { foreach ($line_items as $item_id => $item) { $fee = $cost = 0; $_product = $order->get_product_from_item($item); $shipping_class = $_product->get_shipping_class(); if (isset($woocommerce_flat_rates[$shipping_class])) { $cost = $woocommerce_flat_rates[$shipping_class]['cost']; $fee = $this->get_fee($woocommerce_flat_rates[$shipping_class]['fee'], $_product->get_price()); } elseif ($woocommerce_flat_rate_settings_cost !== '') { $cost = $woocommerce_flat_rate_settings_cost; $fee = $this->get_fee($woocommerce_flat_rate_settings_fee, $_product->get_price()); $matched = true; } $cost_item_id = ($cost + $fee) * $item['qty']; $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true); if (!$flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2)); } } } } } } } } if ($order->has_shipping_method('international_delivery')) { $woocommerce_international_delivery_settings = get_option('woocommerce_international_delivery_settings'); $line_items = $order->get_items('line_item'); if ($woocommerce_international_delivery_settings['enabled'] == 'yes') { if (version_compare(WC_VERSION, '2.5.0', '>=')) { if ($woocommerce_international_delivery_settings['type'] == 'class') { if (!empty($line_items)) { $item_id = false; foreach ($line_items as $item_id => $item) { $wc_international_flat_rate = new WC_Shipping_International_Delivery(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class_id(); $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true); if (!$international_flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id); } } } } } else { if (version_compare(WC_VERSION, '2.4.0', '>')) { if ($woocommerce_international_delivery_settings['type'] == 'class') { if (!empty($line_items)) { $item_id = false; foreach ($line_items as $item_id => $item) { $wc_international_flat_rate = new WC_Shipping_International_Delivery(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class(); $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true); if (!$international_flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id); } } } } } } } } $vendor_shipping_array = get_post_meta($order_id, 'dc_pv_shipped', true); $order = new WC_Order($order_id); $commission_array = array(); $mark_ship = 0; $items = $order->get_items('line_item'); foreach ($items as $order_item_id => $item) { $comm_pro_id = $product_id = $item['product_id']; $variation_id = $item['variation_id']; if ($variation_id) { $comm_pro_id = $variation_id; } if ($product_id) { $product_vendors = get_wcmp_product_vendors($product_id); if ($product_vendors) { if (isset($product_vendors->id) && is_array($vendor_shipping_array)) { if (in_array($product_vendors->id, $vendor_shipping_array)) { $mark_ship = 1; } } $insert_query = $wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->prefix}wcmp_vendor_orders` ( order_id, commission_id, vendor_id, shipping_status, order_item_id, product_id )\n\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t\t\t\t\t\t ( %d, %d, %d, %s, %d, %d ) ON DUPLICATE KEY UPDATE `created` = now()", $order_id, 0, $product_vendors->id, $mark_ship, $order_item_id, $comm_pro_id)); } } } }
/** * 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; }