title: WooCommerce shipping cost calculation in custom shipping method plugin
body: <p>I am trying to create a plugin for WooCommerce that calculates the shipping costs depending on the product weight. I keep on getting this error:</p>
  
  <blockquote>
    <p>Warning: Declaration of WC_Your_Shipping_Method::calculate_shipping($package) should be compatible with WC_Shipping_Method::calculate_shipping($package = Array) in C:\Users\Michelle\Dropbox\MEDIEINSTITUTET\Utveckling mot e-handel\WooCommerce\WC-kurs\wp-content\plugins\frakt\frakt.php on line 18</p>
  </blockquote>
  
  <p>And this is my entire plugin:</p>
  
  <pre><code>&lt;?php 
  /* *
  * Plugin Name: Min frakt modul
    Description: Ett plugin som beräknar frakt kostnad beroende på vikten
  */
  
  /**
   * Check if WooCommerce is active
   */
  
  if (!defined('ABSPATH')) {
      exit;
  }
  
  if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
      function your_shipping_method_init() {
          if ( ! class_exists( 'WC_Your_Shipping_Method' ) ) {
              class WC_Your_Shipping_Method extends WC_Shipping_Method {
                  /**
                   * Constructor for your shipping class
                   *
                   * @access public
                   * @return void
                   */
                  public function __construct() {
                      $this-&gt;id                 = 'mitt-plugin-frakt'; // Id for your shipping method. Should be uunique.
                      $this-&gt;method_title       = __( 'Min frakt plugin' );  // Title shown in admin
                      $this-&gt;method_description = __( 
                      'Frakten skall beräknas på totalvikten av kundvagnen.&lt;br&gt;
                      Listan är följande:&lt;br&gt;
                      &lt; 1kg = 30kr &lt;br&gt;
                      &lt; 5kg = 60kr &lt;br&gt;
                      &lt; 10kg = 100kr &lt;br&gt;
                      &lt; 20kg = 200kr &lt;br&gt;
                      &gt; 20kg = (Vikten * 10)kr' ); // Description shown in admin
  
                      $this-&gt;enabled            = "yes"; // This can be added as an setting but for this example its forced enabled
                      $this-&gt;title              = "My Shipping Method"; // This can be added as an setting but for this example its forced.
  
                      $this-&gt;init();
                  }
  
                  /**
                   * Init your settings
                   *
                   * @access public
                   * @return void
                   */
                  function init() {
                      // Load the settings API
                      $this-&gt;init_form_fields(); // This is part of the settings API. Override the method to add your own settings
                      $this-&gt;init_settings(); // This is part of the settings API. Loads settings you previously init.
  
                      // Save settings in admin if you have any defined
                      add_action( 'woocommerce_update_options_shipping_' . $this-&gt;id, array( $this, 'process_admin_options' ) );
                  }
  
                  /**
                   * calculate_shipping function.
                   *
                   * @access public
                   * @param mixed $package
                   * @return void
                   */
                  public function calculate_shipping( $package ) {
  
                     $alla_items = $package['contents'];
                     $total_weight = 0;
                      foreach ($alla_items as $orderline) {
                          $product_weight = $orderline['data']-&gt;weight;
                          $total_weight += $product_weight;
                      };
  
                      if($total_weight &lt; 1) {
                          $cost = '30';
                      } elseif($total_weight &gt; 1 &amp;&amp; $total_weight &lt; 5) {
                          $cost = '60';
                      } elseif($total_weight &gt; 5 &amp;&amp; $total_weight &lt; 10) {
                          $cost = '100'; 
                      } elseif($total_weight &gt; 10 &amp;&amp; $total_weight &lt; 20) {
                          $cost = '200'; 
                      } elseif($total_weight &gt; 20) {
                          $cost = ($total_weight * 10);
                      } else {
                          echo 'ingen vikt';
                      }
  
                      echo $total_weight;
  
                      $rate = array( 
                          'id' =&gt; $this-&gt;id,
                          'label' =&gt; $this-&gt;title,
                          'cost' =&gt; $cost,
                          'calc_tax' =&gt; 'per_item'
                      );
  
                      // Register the rate
                      $this-&gt;add_rate( $rate );
                  }
              }
          }
      }
  
  
  
      add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' );
  
      function add_your_shipping_method( $methods ) {
          $methods['mitt-plugin-frakt'] = 'WC_Your_Shipping_Method';
          return $methods;
      }
  
      add_filter( 'woocommerce_shipping_methods', 'add_your_shipping_method' );
  }
  
  ?&gt;
  </code></pre>
  
  <p>I really cant find the error... when I try the code I just see "Mici Shipping" but no price at all, meaning that somehow it doesnt read the if else statement?
  Thanks in advance for your help!</p>