Answers.Body: <p>Ok, so what you're doing is returning a new instance of a shipping method class - this class must meet the Shipping Method interface - documented here: <a href="https://craftcommerce.com/docs/shipping-methods#shipping-method-interface" rel="nofollow">https://craftcommerce.com/docs/shipping-methods#shipping-method-interface</a></p>
  
  <p>That is, you must implement each of those functions as defined by the interface in your shipping method class.</p>
  
  <p>You'd define this class in a file of it's own named after the class, and in your base plugin file you <code>require</code> this class definition to bring it in to scope.</p>
  
  <p>The same goes for your shipping rules - you again create a class that meets the interface and then <code>require</code> that in your main plugin file (or wherever you need to access the rule).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-29T16:07:54.290Z
Answers.Text: Am I supposed to extend or implements my custom shipping method class to a specific class? I run into this error: "Argument 2 passed to Craft\Commerce_ShippingMethodsService::getMatchingShippingRule() must implement interface Commerce\Interfaces\ShippingMethod, instance of Craft\MyShippingMethod given"
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-29T18:46:09.753Z
Answers.Text: I figured it out. The shipping method class needed to 'implements \Commerce\Interfaces\ShippingMethod '. Thanks for the help in figuring out how to hook this all up!
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-29T23:46:31.287Z
Answers.Text: Good stuff, glad you're off an running.  The hardest part is the structure - once you have that the actual calculator is usually relatively simple ( - and sorry I am in Aus so hard to respond promptly!)
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-29T03:24:20.780Z
Answers.LastActivityDate: 2016-09-29T04:37:47.303Z
Answers.LastEditDate: 2016-09-29T04:37:47.303Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I'm looking to add additional shipping methods through a plugin, using the documentation here: <a href="https://craftcommerce.com/docs/shipping-methods" rel="nofollow">https://craftcommerce.com/docs/shipping-methods</a></p>
  
  <p>I'm a little bit lost about how to hook things up, according to the docs I'm supposed to do:</p>
  
  <pre><code>public function commerce_registerShippingMethods()
  {
      return [new CustomShipper_CourierDeliveryMethod()];
  }
  </code></pre>
  
  <p>The docs don't really cover where and how to do this, other than to include it in the base plugin file. That part I can follow. Could someone help me understand what file to create, the basics of what it should include and how to connect it (referring to <strong>new CustomShipper_CourierDeliveryMethod()</strong>)?</p>
  
  <p>This is new to me for Craft Plugin development - I'm used to connecting to files using something like:</p>
  
  <pre><code>return [craft()-&gt;pluginHandle_serviceName-&gt;function_name()];
  </code></pre>
  
  <p>Which obviously is very differently than the above. Any help would be HUGELY appreciated.. thanks!</p>
  
Tags: <plugin-development><plugin-craftcommerce><php><classes>
Title: Commerce Custom Shipping Methods via Plugin
ThreadText: # Commerce Custom Shipping Methods via Plugin
  
  (Asked by: username_0 on 2016-09-28)
  
  I'm looking to add additional shipping methods through a plugin, using the documentation here: <https://craftcommerce.com/docs/shipping-methods>
  
  I'm a little bit lost about how to hook things up, according to the docs I'm supposed to do:
  
  ```
  public function commerce_registerShippingMethods()
  {
      return [new CustomShipper_CourierDeliveryMethod()];
  }
  
  ```
  
  The docs don't really cover where and how to do this, other than to include it in the base plugin file. That part I can follow. Could someone help me understand what file to create, the basics of what it should include and how to connect it (referring to **new CustomShipper\_CourierDeliveryMethod()**)?
  
  This is new to me for Craft Plugin development - I'm used to connecting to files using something like:
  
  ```
  return [craft()->pluginHandle_serviceName->function_name()];
  
  ```
  
  Which obviously is very differently than the above. Any help would be HUGELY appreciated.. thanks!
  
  **Tags:** plugin-development, plugin-craftcommerce, php, classes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-29. Score: 3 | Accepted answer
  
  Ok, so what you're doing is returning a new instance of a shipping method class - this class must meet the Shipping Method interface - documented here: <https://craftcommerce.com/docs/shipping-methods#shipping-method-interface>
  
  That is, you must implement each of those functions as defined by the interface in your shipping method class.
  
  You'd define this class in a file of it's own named after the class, and in your base plugin file you `require` this class definition to bring it in to scope.
  
  The same goes for your shipping rules - you again create a class that meets the interface and then `require` that in your main plugin file (or wherever you need to access the rule).
  
  > **Comments:**
  > **username_0**: Am I supposed to extend or implements my custom shipping method class to a specific class? I run into this error: "Argument 2 passed to Craft\Commerce_ShippingMethodsService::getMatchingShippingRule() must implement interface Commerce\Interfaces\ShippingMethod, instance of Craft\MyShippingMethod given"  
  > **username_0**: I figured it out. The shipping method class needed to 'implements \Commerce\Interfaces\ShippingMethod '. Thanks for the help in figuring out how to hook this all up!  
  > **username_1**: Good stuff, glad you're off an running.  The hardest part is the structure - once you have that the actual calculator is usually relatively simple ( - and sorry I am in Aus so hard to respond promptly!)  
  
  ---
  
  