title: Add custom shipping methods in woocommerce using the cart total items
body: <p>I need some help completing this code. I have been trying to make a plugin for my woocommerce site to auto add a shipping cost basing on the total items ordered. ie When I try my code below, It returns a value of eleven irregardless of the number of items I order. Ideal siutation is below:</p>
  
  <p>1-5 packs 5,000
  6-10 packs 10,000
  11-15 packs 15,000
  16-20 packs 20,000</p>
  
  <p>Here is my code below.</p>
  
  <pre><code>&lt;?php
  /*
  Plugin Name: Your Shipping plugin
  Plugin URI: http://woothemes.com/woocommerce
  Description: Your shipping method plugin
  Version: 1.0.0
  Author: WooThemes
  Author URI: http://woothemes.com
  */
  
  
  /**
   * Check if WooCommerce is active
   */
  
  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                 = 'your_shipping_method'; // Id for your shipping method. Should be uunique.
                      $this-&gt;method_title       = __( 'Your Shipping Method' );  // Title shown in admin
                      $this-&gt;method_description = __( 'Description of your shipping method' ); // 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 ) {
                      session_start();
                      global $woocommerce;
  
                      $carttotal = $woocommerce-&gt;cart-&gt;cart_contents_count;
  
                      /*
                          1-5 packs 5,000
                          6-10 packs 10,000
                          11-15 packs 15,000
                          16-20 packs 20,000
  
                      */
                      if($carttotal &lt; 20){
                          $cost = 0;//Free delivery for above 20 packs
                      }else if($carttotal &gt;= 16 &amp;&amp; $carttotal &lt;= 20){
                          $cost = 20000;
                      }else if($carttotal &gt;= 11 &amp;&amp; $carttotal &lt;= 15){
                          $cost = 15000;
                      }else if($carttotal &gt;= 6 &amp;&amp; $carttotal &lt;= 10){
                          $cost = 10000;
                      }else if($carttotal &gt;= 5 &amp;&amp; $carttotal &lt;= 1){
                          $cost = 5000;
                      }else if($carttotal &gt; 1){
                          $cost = 0;
                      }
  
                      $rate = array(
                          'id' =&gt; $this-&gt;id,
                          'label' =&gt; 'Shipping',
                          'cost' =&gt; $cost
                      );
  
                      // Register the rate
                      $this-&gt;add_rate( $rate );
  
                  }
              }
          }
      }
  
      add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' );
  
      function add_your_shipping_method( $methods ) {
          $methods['your_shipping_method'] = 'WC_Your_Shipping_Method';
          return $methods;
      }
  
      add_filter( 'woocommerce_shipping_methods', 'add_your_shipping_method' );
  }
  </code></pre>
  
  <p>I got some help from Credit help: <a href="https://stackoverflow.com/questions/27666501/how-to-add-custom-shipping-charge-in-woocommerce">How to add custom shipping charge in woocommerce?</a> but now I need to complete this. Thanks in advance</p>