Home Forums Plugins CURCY – WooCommerce Multi Currency Shipping method Cost Calculations are Wrong

Shipping method Cost Calculations are Wrong

  • Author
    Posts
  • #166090

    Nishant Vats
    Participant

    My plugin calculates shipping costs and adds a rate to the cart totals. While the calculated costs are correct in the store currency, the calculated converted costs are incorrect. I have pasted my calculate_shipping method in my custom shipping method below. I always end up with a total shipping cost equal to the equivalent of $1… even though the value is correctly calculated when displayed in the store default currency.

    public function calculate_shipping($package = array())
    {
    $weight = 0;
    $cost = 0;
    $country = $package[‘destination’][‘country’];
    if ($country == ‘IN’) {
    $maxQuantity = 0;
    $maxProductWeight = 0;
    foreach ($package[‘contents’] as $item_id => $values) {
    $_product = $values[‘data’];
    $productWeight = $_product->get_weight();
    $weight = $weight $productWeight * $values[‘quantity’];
    if ($productWeight > $maxProductWeight) {
    $maxProductWeight = $productWeight;
    }
    if ($values[‘quantity’] > $maxQuantity)
    $maxQuantity = $values[‘quantity’];
    }
    $weight = wc_get_weight($weight, ‘kg’);
    $weightLimit = (int) $this->settings[‘weight’];
    // Start splitting the package….
    if ($maxProductWeight 0) {
    $numPackages ;
    $weight = min($unsplitWeight, $weightLimit);
    // 1 Compensation of $0.50 Charge Cost per 500g assumed to be USD 1.00
    $priceFromWeight = 1.5 ceil($weight * 2) / 2;
    $costing = $priceFromWeight;
    $cost = $costing; // Increment total cost
    $unsplitWeight -= $weight; // Next iteration of the loop should work on balance weight
    }
    }
    error_log($cost);
    }
    if (!empty($cost)) {
    $rate = array(
    ‘id’ => $this->id,
    ‘label’ => $this->title . ‘ ‘ . nv_wc_shipping_method_hint_html(‘2-3’, __(‘days’, ‘nv’)),
    ‘cost’ => $cost,
    ‘meta_data’ => array(
    ‘split_packages_num’ => $numPackages
    )
    );
    $this->add_rate($rate);
    }
    }

You must be logged in to see replies to this topic. Click here to login or register