php - 将高级自定义字段添加到 Dokan 上的现有表单 - 添加产品和编辑产品页面 (WordPress/WooCommerce)
问题描述
我正在使用多供应商(Dokan)插件,并一直在对其进行自定义。我想要实现并一直在努力的一件事是,我希望单个产品的高级自定义字段(也是一个插件)实际出现在前端,在 Dokan 的卖家仪表板表单之一(编辑产品部分)中。
我希望我的卖家能够在前端页面上选择一个品牌(我的 acf 字段)。
通常当我们添加一个新的 acf 字段组并分配给存档时,该字段将出现在后端。
我发现这很难实现,尤其是将自定义字段添加到现有的前端表单中。
我试图自定义它,我终于让该字段出现在我想要的表单上,但随后出现了另一个问题,即原始表单中的保存按钮不再可点击。
请看截图:https ://gyazo.com/dfb20ed90e773723658979c515581730
这是我尝试添加到 Dokan 的 single-product-new.php 中的代码:
<?php acf_form_head(); ?>
<div class=”dokan-form-group”>
<?php
$product_brand = -1;
$term = array();
$term = wp_get_post_terms( $post_id, ‘brand’, array( ‘fields’ => ‘ids’) );
if ( $term ) {
$product_brand = reset( $term );
}
include_once DOKAN_LIB_DIR.’/class.category-walker.php’;
include_once DOKAN_LIB_DIR. ‘acf.php’;
$brand_args = array(
‘hierarchical’ => 1,
‘hide_empty’ => 0,
‘fields’ => array(‘brand’),
‘name’ => ‘brand’,
‘id’ => ‘brand’,
‘taxonomy’ => ‘brand’,
‘title_li’ => ”,
‘class’ => ‘product_brand dokan-form-control dokan-select2’,
‘exclude’ => ”,
‘selected’ => $product_brand,
‘walker’ => new DokanCategoryWalker( $post_id )
);
acf_form($brand_args);
?>
<div class=”dokan-product-cat-alert dokan-hide”>
<?php esc_html_e(‘Please choose a brand!’, ‘dokan-lite’ ); ?>
</div>
</div>
我知道这是错误的,但不知何故,这些代码帮助我将高级自定义字段拉到我想要的表单上,当您单击更新时,它实际上将字段数据保存到产品中。
我在想也许应该在子主题的function.php下解决这个问题......
任何帮助将不胜感激!
卢克
解决方案
您可以使用名为 ACF Frontend Form for Elementor 的免费插件从前端为您的卖家/供应商添加/编辑产品。 https://wordpress.org/plugins/acf-frontend-form-element/
为此,您还需要使用 elementor 插件并通过 elementor 创建产品页面
推荐阅读
- python-3.x - 当名称在第二行中定义时,Pandas 不读取_csv 原始数据
- python - 将 numpy.float64 转换为整数
- c# - 如何使用 C# Microsoft.Graph 创建回复?
- python - 输出是浮点数而不是整数
- excel - 为什么VB在遍历集合时抛出
- git - 为什么签出最近的提交后我有一个分离的 HEAD?
- scala - 在 Scala 中提取域后缀和计算命中计数
- jetty - 如何动态配置非嵌入式 Jetty 的 servlet 设置?
- php - 使用 Mailgun 的官方 PHP SDK 成功排队邮件时如何读取 API 响应?
- android - 在运行 react-native run-android 时遇到问题