Support » Plugin: WooCommerce » Official custom shipping class doesn’t work anymore (Shipping method api)

  • Hello dear WooCommerce developers.

    Before WooCommerce 3+, using this official WooCommerce code Shipping Method API, it was possible to create a custom shipping class in a plugin.

    Now this code is not working anymore as expected and outputs an error:

    Strict Standards: Declaration of WC_Custom_Shipping_Method::calculate_shipping() should be compatible with WC_Shipping_Method::calculate_shipping($package = Array) in /home/something/www/sites/tie2/wp-content/plugins/custom_shipping_method.php on line 18

    In the provided code (plugin) there is a conflict between existing WC_Shipping_Method::calculate_shipping() method and the calculate_shipping() function declared in the provided code…

    I hope that someone can help to solve this issue.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am also experiencing this issue and asked about it on Stack Overflow: https://stackoverflow.com/questions/45177226/how-to-add-a-custom-working-shipping-method-in-woocommerce-3?stw=2

    Someone there suggested changing:

    public function calculate_shipping( $package ) {

    to this line

    public function calculate_shipping( $package = array() ) {

    It didn’t work for me, but you might have better luck.

    I am also wrestling with this problem at the minute, any help woocommerce? Could you please update your documentation on your website and provide us with a working skeleton?

    This thread is 3 months old c’mon guys…..

    WC_Custom_Shipping_Method is an abstract class and you are trying to change its inherited method calculate_shipping which abstract classes don’t allow.

    Try doing it like this.

    
    class Abs_Custom_Shipping extends WC_Shipping_Method{}
    class WC_Custom_Shipping_Method extends Abs_Custom_Shipping {}
    
    

    ( extend the shipping method into a child class then extend the child into a grandchild class ).

    Hope it makes sense.
    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Official custom shipping class doesn’t work anymore (Shipping method api)’ is closed to new replies.