Support » Plugin: WooCommerce » Custom shipping method not applied to an order even if selected on the checkout

  • intolap

    (@intolap)


    Hello Team,

    I am creating a custom shipping method and tried both ways – Global and Zone. The website sells only in one country i.e. Singapore and they have one zone created for Singapore and added Local Pickup to it.

    I tried using my custom shipping method supporting zone, added it to the Singapore zone. I also tried using my custom shipping method as a global shipping method, not added to any zone. In both the case, I see the shipping option on the checkout page, but the order always goes to Local pickup.

    I tried removing Local pickup from the shipping zone and then my custom shipping method works fine. Why this? Can’t I use Local and custom both. Please help.

    Best regards,
    Debashis

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support laceyrod a11n

    (@laceyrod)

    Automattic Happiness Engineer

    Hi @intolap

    Thanks for reaching out, and I’m sorry to hear of the troubles!

    I understand that you’re not able to select Local Pickup as an option in checkout when your custom shipping method is also added either globally or via Shipping Zones.

    Further debugging this would require analyzing the custom code of your shipping plugin and would require more complex development since you’ve created that shipping method from scratch. I’ll go ahead and leave this thread open for a while in case anyone else wants to chime in, but in the meantime, I can also recommend the following resources for more development-oriented questions:

    – WooCommerce Slack Community: https://woocommerce.com/community-slack/
    – Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/

    Hope this helps.

    Thread Starter intolap

    (@intolap)

    Hello @laceyrod,

    Thank you for your prompt response. The site already has a zone for Singapore with a Local pickup method in it. I just added a custom shipping method, tried both global and zone variation. But every time I select the custom shipping on the checkout page, the order always saves as a Local pickup method.

    To cross-check I tried the skeleton shipping method define where https://docs.woocommerce.com/document/shipping-method-api/ but I face the same issue. I have followed the exact guidelines laid down by Woocommerce to create my shipping method. I have developed several shipping methods before following the same guidelines but never faced this issue.

    Just to emphasize, calculate_shipping() is working perfectly and so I am able to select my custom shipping method on the checkout page. On selecting the cart total also updates. But after placing the order finally, the order saves Local pickup.

    That’s it!

    How do you want me to share the codes to check? Here or on the other channels you mentioned?

    Best regards,
    Debashis

    Plugin Support laceyrod a11n

    (@laceyrod)

    Automattic Happiness Engineer

    Hi Debashis,

    Thanks for your detailed response!

    Let’s actually take a step back here if you don’t mind. It sounds like you are actually able to select your custom shipping method in the cart/checkout, but it’s only after the order is placed that the Local Pickup is showing in the backend, is that correct?

    If so, can you confirm that you’ve tested your custom plugin with just WooCommerce and a default theme active, like Storefront? This will help us rule out any third-party conflicts that could be contributing to this. Also, would you mind copying and pasting your System Status Report into this thread so that we can check for any red flags there? You can find this by going to WooCommerce > Status > System Status > Get System Report in your WP-Admin dashboard.

    Let’s take a look at how it performs with just a default installation, and if you can confirm that the problem still happens in that environment, then it would point us more towards the custom code being the issue.

    Thanks!

    Thread Starter intolap

    (@intolap)

    Hello @laceyrod,

    Yes, you are correct.

    I find it strange that the issue happens when we assign the cost to the add_rate function. Actually I am fetching the shipping rates from an API which returns JSON response {“totalFee”:”15″,”totalFeeCurrency”:”SGD”}

    Now, when I json_decode this response and assign the totalFee to the cost, it does not accept.

    Doesn’t work:
    $response = json_decode({“totalFee”:”15″,”totalFeeCurrency”:”SGD”}, true);
    $cost = $response[‘totalFee’]; // I tried intval(), floatval(), strval()

    $rate = array(
    ‘id’ => $this->id,
    ‘label’ => $this->title,
    ‘cost’ => $cost
    );
    $this->add_rate($rate);

    Works:
    $rate = array(
    ‘id’ => $this->id,
    ‘label’ => $this->title,
    ‘cost’ => 10
    );
    $this->add_rate($rate);

    –OR–
    $cost = 10;
    $rate = array(
    ‘id’ => $this->id,
    ‘label’ => $this->title,
    ‘cost’ => $cost
    );
    $this->add_rate($rate);

    Hope this gives a vision of where I am doing wrong.

    Best Regards,
    Debashis

    • This reply was modified 1 year ago by intolap.
    Thread Starter intolap

    (@intolap)

    Hello @laceyrod,

    Unfortunately, I have not received any response from the woocommerce slack community yet. Any other suggestions?

    Best regards,
    Debashis

    Thread Starter intolap

    (@intolap)

    Hello Team,

    Any update?

    I dig more into the situation and noticed one pattern.

    In calculate_shipping() function I am fetching the shipping cost via an API. So, showing the cost on the checkout page is all good. But when I select that shipping method and place an order this issue occurs.

    Putting some intermediary logging, I found a strange behavior defined below.

    On checkout page: Makes the API call and shows the shipping fee.

    (Log says)
    2021-01-19T12:27:54+00:00 INFO {“totalFee”:”12.00″,”totalFeeCurrency”:”SGD”}

    After placing an order: Makes the API call again but fails because it does not find the billing name and phone (required by the API).

    (Log says)
    2021-01-19T12:28:20+00:00 INFO {“message”:”ERR_REQUIRED_FIELD”,”detail”:”Failed to validate data: validator 0xc01cfa6ed0 failed: object property ‘deliveries’ validation failed: object property ‘toContact’ validation failed: object property ‘name’ validation failed: string ” does not match regular expression ‘.+'”}

    Hence it falls back to the other available shipping method in the list to complete the order.

    Can you please explain why woocommerce doesn’t find the checkout fields (name and phone) when the order is placed?

    Eagerly looking forward to a response.

    Best regards,
    Debashis

    Thread Starter intolap

    (@intolap)

    Hello @laceyrod,

    I managed to debug the issue. But I have a question.

    In my custom shipping plugin “calculate_shipping()” function, I need the billing_first_name, billing_last_name, billing_phone. I am able to get these details using –

    WC()->checkout->get_value(‘billing_first_name’)
    WC()->checkout->get_value(‘billing_last_name’)
    WC()->checkout->get_value(‘billing_phone’)

    I tried using,

    WC()->session->get_value(‘billing_first_name’)
    WC()->session->get_value(‘billing_last_name’)
    WC()->session->get_value(‘billing_phone’)

    The above works when I am a returning customer and logged in. But the same doesn’t work when I am a new customer and is not logged in.

    I just need the three form field values regardless of the login or logout state of the customer. Can you please help?

    Best regards,
    Debashis

    Thread Starter intolap

    (@intolap)

    Hello @laceyrod,

    Now I am facing another issue.

    My custom shipping method supports zones.

    $this->supports = array(
    ‘shipping-zones’,
    ‘instance-settings’,
    ‘instance-settings-modal’,
    );

    When I add this shipping method to a zone. This is not updating the settings if I make any changes https://www.peopleperhour.com/web/aHR0cHM6Ly93d3cubG9vbS5jb20vc2hhcmUvNGMzN2IxYjBlYjNjNDc5ZGFkYTBiZmFkZDAxMWViMGE%3D

    Any clue why this issue?

    Regards,
    Debashis

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom shipping method not applied to an order even if selected on the checkout’ is closed to new replies.