提问人:Titus 提问时间:9/27/2023 最后编辑:Titus 更新时间:9/27/2023 访问量:20
如何在 woocommerce wordpress 中将 wordpress 表单中的数字输入捕获到 acf 字段中
How to capture number input from wordpress form into acf field in woocommerce wordpress
问:
WUFP 电话字段我正在尝试使用高级woocommerce 自定义字段为电话无自定义字段插件捕获在我的 woocommerce 网站上提交表单的客人的电话号码。我注意到他们输入的电话号码没有存储到可供他们使用的 woocommerce 产品电话字段中。如果有一种特殊的方法可以捕获它并确保它留在盒子里,请告诉我。访客产品前端 woocommerce 表单是使用 wordpress 用户前端插件创建的,而在 woocommerce 产品数据中添加电话无字段的自定义字段是使用 ACF 插件创建的。然后我确保电话字段 meta 和 Acf 电话 meta 具有相同的字段,即 phone_field。
我已经在下面编写了代码
// Hook into form submission (replace 'my_form_id' with the actual form ID)
add_action('wpuf_add_post_form_top', 'update_product_acf_field_guest_submission', 10, 3);
function update_product_acf_field_guest_submission($form_id, $form_settings, $post_args) {
// Check if the form ID matches the specific form where the phone number is submitted
if ($form_id == '356') {
// Get the submitted phone number from the form
$phone_number = sanitize_text_field($_POST['phone_field']);
// Update the ACF field for the WooCommerce product
update_field('acf[field_6512315ee37ae]', $phone_number, $post_args['post_id']);
}
}
答: 暂无答案
评论