【发布时间】:2022-01-17 03:33:16
【问题描述】:
所以我一直在对整个网站进行重组构建,其中一部分涉及从强大的形式切换到重力形式。我们这样做是因为我们想使用嵌套表单功能,这样我们就可以自动化多个参与者,而不必为每个参与者创建一个新表单。
这就是问题所在 - 在我们通过 Formidable 为每位参与者提供单独表格的旧网站上,我们有一个代码使用 Canvas API 将姓名和电子邮件信息发送到 Canvas 并自动为该公司提供的在线课程注册用户。在尝试将此代码的部分转换为使用我的嵌套表单时,我遇到了一个障碍:
-
主要问题是该值作为嵌套表单条目中的所有信息被吐出,而不是按名称/电子邮件/等。
-
信息被吐出两次,可能是因为表单的结构方式?表单/嵌套表单中发生了一些计算,所以我将其记录下来。
[1] => WC_Meta_Data Object
(
[current_data:protected] => Array
(
[id] => 212
[key] => Attendee Registration
[value] =>
Name
Test Name
Email Address
courses@email.com
Cell Phone
(333) 333-3333
Would you like to receive text message reminders for this registration?
No
Post-class notification is required for the following states, please identify if you will be using this class to fulfill any state license requirements:
N/A
You'll receive a hard copy and digital certificate upon course completion. Additional options are available here:
All live classes include a hard copy manual and regulations. To join our effort to save paper, please also add any of the following options to take your books home:
)
[data:protected] => Array
(
[id] => 212
[key] => Attendee Registration
[value] =>
Name
Test Name
Email Address
courses@email.com
Cell Phone
(333) 333-3333
Would you like to receive text message reminders for this registration?
No
Post-class notification is required for the following states, please identify if you will be using this class to fulfill any state license requirements:
N/A
You'll receive a hard copy and digital certificate upon course completion. Additional options are available here:
All live classes include a hard copy manual and regulations. To join our effort to save paper, please also add any of the following options to take your books home:
)
)
另外:我正在尝试通过 [_gravity_form_linked_entry_id] 获取主条目的 ID,并通过 [_gravity_form_lead] 从中获取嵌套信息。
我能从中得到的最好的结果就是......所以如果有人有任何指示,我有点迷失了如何在这里取得进展!非常感谢!
[data:protected] => Array
(
[id] => 211
[key] => _gravity_forms_history
[value] => Array
(
[_gravity_form_cart_item_key] => 72201a9586fb30895b8fb5cac2a796b9
[_gravity_form_linked_entry_id] => 125
[_gravity_form_lead] => Array
(
[form_id] => 1
[source_url] => https://chcv2.flywheelstaging.com/product/air-monitoring-specialist-live/
[ip] => 75.151.95.41
[42.1] => Course Price
[42.2] => $580.00
[42.3] => 1
[21] => 122
[40.1] => Add-On Fees
[40.2] => $0.00
[40.3] => 1
)
[_gravity_form_data] => Array
(
[id] => 1
[bulk_id] => 0
[display_title] =>
[display_description] =>
[disable_woocommerce_price] => no
[price_before] =>
[price_after] =>
[disable_calculations] => no
[disable_label_subtotal] => yes
[disable_label_options] => yes
[disable_label_total] => no
[disable_anchor] => no
[label_subtotal] => Course Fee
[label_options] => Additional Attendees + Selected Options
[label_total] => Attendee Registration + Add-Ons:
[use_ajax] => no
[enable_cart_edit] => no
[enable_cart_edit_remove] => no
[keep_cart_entries] => no
[send_notifications] => no
[enable_cart_quantity_management] => stock
[cart_quantity_field] =>
[update_payment_details] => yes
[display_totals_location] => after
[structured_data_override] => no
[structured_data_low_price] =>
[structured_data_high_price] =>
[structured_data_override_type] => overwrite
)
)
)
更新:以下是我从 Rochelle 的评论中合并代码的方式,但出现错误
add_action( 'woocommerce_thankyou', 'canvas_enroll', 20, 2 );
function canvas_enroll($orders) {
$query = new WC_Order_Query( array(
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
) );
$orders = $query->get_orders();
foreach($orders as $order){
foreach ($order->get_items() as $item_id => $item_data) {
if(isset($item_data->get_meta( '_gravity_forms_history')["_gravity_form_lead"]["form_id"]) && !empty($item_data->get_meta( '_gravity_forms_history')["_gravity_form_lead"]["form_id"])){
$linked_entry=$item_data->get_meta( '_gravity_forms_history')["_gravity_form_linked_entry_id"];
$entry_id = $linked_entry;
$entry = GFAPI::get_entry( $entry_id );//id of Parent Gravity Form
if(isset($item_data->get_meta( '_gravity_forms_history')["_gravity_form_lead"]['2']) && !empty($item_data->get_meta( '_gravity_forms_history')["_gravity_form_lead"]['2'])){
$linked_nested_value=$item_data->get_meta( '_gravity_forms_history')["_gravity_form_lead"]['2'];
$nested_value_array = preg_split ("/\,/", $linked_nested_value); //array of child entries
$child_entry_amt = substr_count($linked_nested_value, ",") + 1;
if ($child_entry_amt > 0){
for ($n = 0; $n < $child_entry_amt; $n++) {
$entry_id_nest[$n]=$nested_value_array[$n];
$entry_nest[$n] = GFAPI::get_entry( $entry_id_nest[$n] ); //nested form entry
$name[$n] = $entry_nest[$n]['12.3'].''.$entry_nest[$n]['12.6'];//replace 1.3 and 1.6 with nested field id of name
$email[$n] = $entry_nest[$n]['11']; //2 is the GF nested field id of email
}
}
}
}
}
}
}
【问题讨论】:
-
我不太确定我在看什么,但我想我做过类似的事情。这是带有重力形式附加组件的 woocommerce 产品吗?我只是在查看 woocommerce 元数据的 var_dump 吗?
-
嘿,Rochelle,这正是您所看到的!它是一款带有 GF 附加组件的 WC 产品。这里棘手的部分是还有一个嵌套表单插件,我无法从 GF 表单中的嵌套表单中获取特定字段。
标签: wordpress nested-forms elementor gravity-forms-plugin gravityforms