什么,我试图完成的:在woocommerce,我需要通过AJAX相应检查通过,当用户选择日期的日期选择器领域的交付日期,然后更新运输选项,让事情当他们是不恰当的。像免费送货,可拍摄出
What i'm trying to accomplish: In woocommerce, I need to check a date delivered via a datepicker field when user selects a date, and then update shipping options accordingly via ajax, so that things like free shipping can be taken out when they are not appropriate.
我目前知道/想通了:我现在有jQuery的事件发射,并通过日期自定义脚本,这是有点儿,我需要做的发送。我一直没能找到只返回航运数据woocommerce类中的函数,所以我不认为我可以调用,并返回一个片段,因为他们的结账已经这样做了。
What I currently know/have figured out: I currently have the jQuery event firing and sending through a date to a custom script, which is kinda where I need to do. I have not been able to find a function within woocommerce classes that returns just the shipping data, so I don't think I can call that and return it as a fragment, as they do for the checkout already.
不过,我也发现,
WC_AJAX::update_order_review()
已经在它的行动电话,我已经成功地勾住了功能上的行动,我已经能够关火
has an action call within it, and I have successfully hooked a function onto that action, AND i've been able to fire off the
t( 'body' ).trigger( 'update_checkout' );
这触发了一个更新结帐检讨块的动作。
which fires off the action that updates the checkout review block.
我真正的问题:这一切是伟大的,I'ts看起来像它的方向是正确的航向,但我不知道woocommerce不够好,知道如何让内部的运输方式我迷上行动,他们在必要时取消设置。有谁知道,如果我可以通过$ woocommerce全局对象得到他们,然后让他们被那个WC_AJAX方法??
My real question: All this is great, and I'ts looking like its heading in the right direction, but I don't know woocommerce well enough to know how to get the shipping methods within my hooked action to unset them as necessary. Does anyone know if I can get them through the $woocommerce global object, and then have them be read by the rest of that WC_AJAX method??
在这里任何帮助将是很大的AP preciated。
Any help here would be greatly appreciated.
**注:是的,我知道,那是一个T,而不是一个$的jQuery的。不是一个错误
** notes: yes, I know thats a 't' and not a '$' in the jQuery. Not a mistake
因此,对于那些你们谁需要这一点,就需要一点点finagling在woocommerce,的方式,因为他们处理的车/结帐值输出运费和付款方式,但最终,我可以做到这一点使用woocommerce的钩子,很少插件的修改,因此,一个pretty的清洁解决方案。
So, for those of you who may need this, it required a little finagling in woocommerce, because of the way they handle output of cart/checkout values for shipping and payment options, but in the end, I could make it happen using woocommerce's hooks, and very little plugin modification, so, a pretty clean solution.
基本上我所做的就是利用woocommerce会议,两个挂钩,和一个JavaScript触发器,刷新结账订单审核。
Basically what I did was use woocommerce sessions, two hooks, and a javascript trigger that refreshes the checkout order review.
通过的 woocommerce_checkout_update_order_review
挂钩,发生在 WC_AJAX :: update_order_review
和使用前述方式的组合 $('身体').trigger('update_checkout');
电话,我可以钩到该更新结帐检讨块的动作。到目前为止好。
Through a combination of the woocommerce_checkout_update_order_review
hook that happens in the WC_AJAX::update_order_review
and use of the aformentioned $( 'body' ).trigger( 'update_checkout' );
call, I could hook in to the action that updates the checkout review block. So far so good.
我在这个函数所做的是检查是否领域已拥有一个值,如果它这样做,将其保存在 WC() - >会议
。然后,因为 WC_AJAX :: update_order_review
通话 woocommerce_order_review()
来获取所有更新的车和运输方法,我看着与函数模板关联,并发现了另一个挂钩, woocommerce_review_order_before_shipping
,这让我修改的运送方式的车模板遍历并建立运输方式在之前 wc_cart_totals_shipping_html()
。
What I did in this function was check if the field had a value, and if it did, save it in the WC()->session
. THEN, since WC_AJAX::update_order_review
calls woocommerce_order_review()
to grab all the updated cart and shipping methods, I looked into the template associated with that function and found another hook, woocommerce_review_order_before_shipping
, which allows me to modify the shipping methods before the cart template loops through and builds the shipping options in wc_cart_totals_shipping_html()
.
现在,我知道,你在想,等一下,我需要结账的发运方式,没有车的人,但在现实中,他们似乎是同一个。
Now, I know, you're thinking, wait, I need checkout shipping methods, not cart ones, but in reality, they seem to be one and the same.
希望我浪费的时间会帮助别人有类似的问题。
Hopefully my wasted hours will help someone else with a similar problem.
干杯。