These docs are for v2023.01. Click to read the latest docs for v2024.09.

Discussions

Ask a Question
Back to All

Bugs in WooCommerce Plugin

Hi,

You have 2 bugs in your WooCommerce plugin.

  1. The weight_to_kg function is converting kilograms to grams, and not the other way around. This is due to an incorrect comparison operand
if ( 'g' !== $weight_unit ) { // <-- this should be 'g' === $weight_unit
			$weight = $weight * 0.001;
		} elseif ( 'lbs' === $weight_unit ) {
			$weight = $weight * 0.453592;
		} elseif ( 'oz' === $weight_unit ) {
			$weight = $weight * 0.0283495;
		}
  1. Then, in your calculate_shipping function, you are using the product dimensions and weight to calculate the shipping cost instead of using the cart items values. Certain plugins or custom implementations can programmatically change these values for cart items, but the cost is always calculated with the static values set in the backend.

In class-easyship-shipping-method.php, replace the $product variable with $item['data'] on likes 395-398.

$items[] = array(
				'actual_weight'          => $this->weight_to_kg( $item['data']->get_weight() ),
				'height'                 => $this->default_dimension( $this->dimension_to_cm( $item['data']->get_height() ) ),
				'width'                  => $this->default_dimension( $this->dimension_to_cm( $item['data']->get_width() ) ),
				'length'                 => $this->default_dimension( $this->dimension_to_cm( $item['data']->get_length() ) ),

Please let me know if these changes will be implemented in the next update :)

Thanks!