Custom Shipping Rate - php

I'm trying to customize my onepage checkout in magento. The process is to place orders to the company. Apparently I have set a custom table rate in magento where in I have 2 choices. First choice is Victoria (Australia), where in depending on item size there is a fixed rate for that, while the rest of Australia has the same rate.
Apparently when I use my onepage checkout, I encounter 2 errors:
1st error is that when I am in guest mode, when I fill up the billing information, after I go to the shipping method, it says that my shipping method is unavailable, even if I had already inputted the correct address.
My second error is that when I am using a customer account, everything works fine for the 1st time, then if I try to place another order, it shows the error.
I'm thinking of two ways right now to solve it:
Since I need to fix the problem right away, could I remove the shipping method altogether and just create my own computation at the review tab and save the shipping fee in the end?
Or I try to fix the problem on how the shipping method works?

I found matrix-rate free plugin for magento online. A great alternative instead of manipulating it in the backend. I tried it and it immediately worked, though you need to check if you have the data you need in your database. Use the same steps as you were in modifying table rates, as there will be a new tab for the matrix-rate plugin in the configuration->shipping methods tab.

Related

How to calculate dynamic shipping amount based on address in Magento 2.4

In my shopping card build using Magento2.4.2 , I need a dynamic calculation of shipping amount after going to next step after entering the shipping address. What I need is to make a third party API call to calculate shipping value based on address entered. I begin with the following URL but It gives a static shipping value only. I have attached the screenshot of step1 and step2 which will make some sense of what I need. I want to customise the module given in the link to achieve this. I have referenced many articles but could not find a solution. Someone please help to achieve this. The code I have added in same as in the link here
Step 1 : After entering address
Step 2 : Before finalising payment. Here the shipping should not be 0 it should vary according to the address value
Note: I can manage to do the third party call, leave it for me, What I need is to get is where to hook the Magento to modify the shipping value.
There is a good module to handle this kind of things that you may want to take a look at. I think it answer perfectly what you are trying to achieve. Owebia Shipping methods : https://owebia.com/doc/en/magento2-module-advanced-shipping
It's allowing you to add a config file that determines all available shipping methods, specify the prices using all the information you want from the cart and much more.

Disable Automatic cart/checkout_update add manual option to update before placing order

Current Issue:
My checkout calculator refreshes shipping rates way too often, currently it update/refreshes shipping rates when I change a payment method, or I choose a different shipping method as well as when I change an address field or modify a quantity in cart & it even does one upon cart opening in browser. (I understand some merchants may need these to update due to fees associated with certain payment gateways or shipping methods, but to me why do I need to pull live shipping rates again when all I did was click on local pickup, or something that shouldn't have any affect at all on shipping carrier rates)
What I'm trying to accomplish:
I would like the checkout/cart calculator to stop auto update/refresh shipping rates all together until the end of checkout where it should place 1 after I've entered all attributing factors into appropriate fields necessary to make the call, at least IMO.
I have read through hundreds of posts but all I'm turning up is ways to ensure checkout calculator refreshes on certain Ajax calls I need it to be disabled for any factor. I'm still pretty new here so I apologize if I'm breaking some protocols please forgive, and any help will be greatly appreciated.
Update:
After thinking on this some more I feel a perfect solution (if possible) would be to place a button in the checkout calc shipping area, or down by the place order button that would allow me or a customer to manually pull the shipping rate API and update totals when necessary and do away with the entire automatic process(this would also benefit me in that woocommerce would stop trying to make a new call after every keystroke), but this would also necessitate the need for a function or something the like to keep an order from being placed unless this manual button had been pressed immediately prior to place order button (and they would need to press it again upon making any address field changes, or changing a shipping method or any other factor that would affect the order totals, exclude things like name, phone number, Company Name, or any other field you can think of that wouldn't affect order total at all).
8 hours later -
I'm still banging my head at this no real results. The only thing I've accomplished is hiding the shipping calc in the cart with this
function disable_shipping_calc_on_cart( $show_shipping ) {
if( is_cart() ) {
return false;
}
return $show_shipping;
}
add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'disable_shipping_calc_on_cart', 99 );
But it doesn't actually stop the API call just hides it. Although I think some time may be saved not having to generate the UI for the field, it's a negligible amount. If only cart would just display order total/tax breakdown like it does in desktop drop down or mobile sidebar that would speed my cart experience up a whole lot. Either way I prefer it not to be in the cart.
Depressing, if only the whole automated update waited for a button press at the end I would save so much time. As well as my customers. I mean doesn't this make sense. Let me describe my workflow through rounds of testing. Eight payment gateways custom configured with rules granting visibility need to all be tested through every variable & here is how it apparently must be done to test the front end(At least in my case, I'm very new to this & I never even considered building a website until I was approached 3-4 months ago about it). I'll shorten the entire experience by going right to the part where I'm entering the cart with 1 of my many orders.
cart opens in browser... Shipping API call 10-15 sec for callback, Update some order quantities if needed... Shipping API call 10-15 sec,(as stated above there is no shipping calc visible here. So thank god I can not be tripped up by another... Shipping API call 10-15 sec while still in the cart), Proceed to checkout, Account credentials auto populate fields... Shipping API call 10-15 sec, I may need to test shipping across a larger distance or commercial/residential rates so change address fields.... shipping API call 10-15 sec, Select Shipping Method... Shipping API call 10-15 sec, Select payment method & ... yep Shipping API call 10-15 sec..... & finally I can place the order through the front end. :( sound exhausting to you? wouldn't it make sense to bypass all those Shipping API calls and just done 1 at the very end of checkout? Hmm that's like 2 min of potentially lost time in the checkout experience. That call ould have been resolved in 1, 10-15 sec manual button press to update.
IDK something like 10 hours in now... I had a little more progress made when I removed update_totals_on_change from all checkout fields but ZIP code. I left ZIP enabled because I was afraid this method might allow you to run through the rest of the order process. Then come back to shipping fields change address and not trigger an update_total and have the order process. At this point I'm not sure if this was necessary or not but I thought if any factor truly affected the order total it would be the zip code & my shipping API will not let an order process if all the other address fields don't correlate with the zip code. So I though better safe. So that will save a bundle of time for those fields(although those fields don't lockout upon API call the way shipping and payment radios do, but at least it saves u waiting on 1 after the very last keystroke. Unless that last keystroke is in the ZIP field, hmm I may need to relocate the field farther up the form to allow it to get started earlier in the process. Whoops long tangent but thinking aloud...) hmmm if only the automated process allowed you to toggle these radios during its call you could potential complete the order in one sitting and allow the process to do its thing the whole time finally resolving itself at the end, seems a little inefficient overhead wise, but is sounding like the most rational idea I've thought of yet...Yeah, unlock all fields/radios, whatever.... while the API is processing... what I'm getting at is a way to get at the greyed out areas that have no way to be interacted with during the update/refresh... Any ideas?
Next day-
After passing out in my labor I didn't have time to test what removing update_totals_on_change from shipping fields did. Unfortunately I discovered this morning that this accomplished nothing. All address fields still auto update on change, disappointing. I'm considering adding better usability plugin to allow for quantity changes at checkout. This would at least eliminate any need to go to the cart page. So that could cut out a step or two.
Another Update:
So I found this bit of code in wp-content/plugins/woocommerce/templates/checkout/payment.php
<?php esc_html_e( 'Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce' ); ?>
<br/><button type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php esc_attr_e( 'Update totals', 'woocommerce' ); ?>"><?php esc_html_e( 'Update totals', 'woocommerce' ); ?></button>
</noscript>
So there seems to be something that will propogate said button if your browser does not support java script. However, I would not want to disable javascript for my whole site, but maybe I can disable it on checkout only and it won't affect much other than generating the above button at checkout. Looking into this, again any advice would be greatly appreciated.
New Info-
So after turning this over again and again. I discovered that by disabling jquery-blockui script It will then allow me to change any field in checkout without locking up during call. However when disabled there is no call being placed upon field changes, so I need to find a way to initiate the call manually and then lock it up somehow so customer must update immediately prior to placing order.
Not a complete answer to your issue but I am struggling with EXACTLY the same problem.
Woocommerce shipping modifications required to support HTTP API shipping calcs
Though I have managed to stop it calling out and calculating the shipping on cart item addition/modification by adding the following to calculate_Shipping method of my custom shipping plugin.
if ('https://aaa.bbb/checkout/' !== $_SERVER['HTTP_REFERER']) {
return;
}
I am starting to think I need to do the same as you were working on by adding a calculate shipping button that must be pressed before ordering. It must also be run again after any address update before checkout was allowed to be completed.
Did you solve your problem in the last months? If so would appreciate your solution!?!

Is it possible to hide the shipping method step on magento checkout process

Is it possible to hide the shipping method step on the magento checkout process. I want to remove the shipping method step only on checkout page, not permanently.
What i am trying to achieve is on the cart page when the customer enters his postcode for shipping estimate and then update total. I will want to use his choice he made here for his order. So I see no relevance for him to alter his shipping choice afterwards as I only have one shipping option.
I have searched around and found there are ways of removing the step altogether and enabling a default shipping method. However I am using a table matrix so the shipping charge differs based on postcode entered, so i can not set it as a default.
Please can you advice if it is possible to achieve what I want and if so how would I approach it.
Advice and guidance is appreciated.
Thanks

Opencart 2.0.1.1: delivery method first time it displays and second time no display

I altered some coding in checkout/checkout.tpl to hide the shipping details section and take shipping details from the billing details
it was working perfectly but now delivery method some time it displays and second time no display... don't know what gone to be wrong
Opencart 2.0.1.1
my code goes checkout/checkout.tpl
http://pastebin.com/d6AmGPzf
I worked with your code its working fine, i think in some products you might missed to choose the option for shipping required one, choose it as Yes
goto>
Home>>Products>>edit product(check for all products) data (under data)
find this and choose it as yes

How do I add custom shipping and payment options to checkout in Magento?

Running Magento 1.5.1. My webstore contains a lot of products that get shipped direct from the manufacturer. The cost of shipping is extremely variable, and due to the number of products we carry, it is unfeasible to determine shipping costs for many items.
I would like to add a "request quote" option during checkout. The basic idea I have is this:
-Items without a weight or dimensions will be required to go through an RFQ (request for quote) process. During checkout, if the user has an item in their cart that requires an RFQ (because it doesn't have weight or dimensions defined), it will present a single option for shipping: "Request quote for shipping".
-The next step is the payment screen. Instead of actual payment options, a "pay invoice later" or "pay when quote is received" option will be present. The user will be forced to select this (or perhaps we could skip the payment screen altogether?).
This seems like it should be relatively easy to hack together, but I'm wondering if I'm going about this the wrong way? Is there an easier way to do this? My thought is to modify the checkout code to check for weight or dimensions, if not, only show that one shipping option (I'd probably re-purpose "free shipping" to be that option). Then, in the payment screen, check if free shipping is selected in the order, and then present the custom payment option (probably re-purpose cheque or money order option). From there we'd send them an official quote via Paypal or something similar.
Any thoughts? Thanks!!
I'll offer my normal advice: There are a ton of extensions to let this happen. My philosophy is to start looking at extensions before trying to code anything in magento. Is especially helpful when an upgrade breaks something; they'll usually fix upgrade problems that clearly affect their own extensions for free.
In your case there is a free custom shipping option extension I use for "Will Call" which you can use for "RFQ" purposes. I strongly advise against messing with payment modules. I have written 6 or more "payment" things in PHP for live sites and admin back-end use. Until you really understand Magento, you are wasting your time and money writing code. If your question is to get a website working so you can make money, go buy extensions that get the job done...
To go on about writing code, I hand rolled some code in the contact form to add google re-capcha as well as to have customers select from existing product attributes (vehicle year, make, model). I was eventually able to figure out how to have these reflect in the emails we get from the contact form, however, there is no database persistence, which is the proper solution. Further, mucking about in the code quickly and easily breaks Magento in unexpected and surprising ways, hence why my normal Magento reply on here is to strongly urge people to buy extensions. If you're asking the kind of questions like I would ask, you don't know enough to make a professional extension... buy a few proper extensions, analyze them, spend lots of time trying to figure it out.
Any more there are plenty of extensions competing to do the same tasks, so there should be something already working to do what you want.

Categories