【问题标题】:Add Advanced Custom Field to existing form on Dokan- Add product & edit product page (WordPress/WooCommerce)将高级自定义字段添加到 Dokan 上的现有表单 - 添加产品和编辑产品页面 (WordPress/WooCommerce)
【发布时间】:2020-01-20 01:50:58
【问题描述】:

我正在使用多供应商 (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 下解决这个问题...

任何帮助将不胜感激!

卢克

【问题讨论】:

    标签: php html wordpress woocommerce dokan


    【解决方案1】:

    您可以使用名为 ACF Frontend Form for Elementor 的免费插件从前端为您的卖家/供应商添加/编辑产品。 https://wordpress.org/plugins/acf-frontend-form-element/

    为此您还需要使用elementor插件并通过elementor创建产品页面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2018-04-30
      • 2021-07-17
      • 2018-11-07
      相关资源
      最近更新 更多