简体   繁体   English

将高级自定义字段添加到 Dokan 上的现有表单 - 添加产品和编辑产品页面 (WordPress/WooCommerce)

[英]Add Advanced Custom Field to existing form on Dokan- Add product & edit product page (WordPress/WooCommerce)

I'm using a multi-vendor (Dokan) plugin, and been customizing it.我正在使用多供应商(Dokan)插件,并一直在对其进行自定义。 One thing I want to achieve and been struggling is that I want my advanced custom field(also a plugin) for single product to actually appear on the front-end, in one of the Dokan's seller dashboard form (Edit product section).我想要实现并一直在努力的一件事是,我希望单个产品的高级自定义字段(也是一个插件)实际出现在前端,在 Dokan 的卖家仪表板表单之一(编辑产品部分)中。

I want my seller to be able to select a brand (my acf field) on the fron-end page.我希望我的卖家能够在前端页面上 select 一个品牌(我的 acf 字段)。

Normally when we add a new acf field group, and assign to the archive, the field will appear on the backend.通常当我们添加一个新的 acf 字段组并分配给存档时,该字段将出现在后端。

I found this to be pretty hard to achieve, especially adding the custom field onto an existing front-end form.我发现这很难实现,尤其是将自定义字段添加到现有的前端表单中。

I have trying to customize it and I finally get the field to appear on the form I want to, but then another problem came up, which is the save button from the original form isn't clickable anymore.我试图自定义它,我终于让该字段出现在我想要的表单上,但随后出现了另一个问题,即原始表单中的保存按钮不再可点击。

Please see screenshot: https://gyazo.com/dfb20ed90e773723658979c515581730请看截图: https://gyazo.com/dfb20ed90e773723658979c515581730

and here is the code I attempted to add into my Dokan's single-product-new.php:这是我试图添加到我的 Dokan 的单一产品新的代码。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>

I know this is wrong, but somehow these code helped me to pull the advanced custom field onto the form I want, and it's actually saving the field data to the product when you click update.我知道这是错误的,但不知何故,这些代码帮助我将高级自定义字段拉到我想要的表单上,当您单击更新时,它实际上将字段数据保存到产品中。

I was thinking maybe should of work around this under child-theme's function.php...我在想也许应该在儿童主题的 function.php 下解决这个问题......

Any help will be really appreciated!任何帮助将不胜感激!

Luke卢克

You can use a free plugin named ACF Frontend Form for Elementor to add / edit products from front end for your sellers / vendors.您可以使用名为 ACF Frontend Form for Elementor 的免费插件从前端为您的卖家/供应商添加/编辑产品。 https://wordpress.org/plugins/acf-frontend-form-element/ https://wordpress.org/plugins/acf-frontend-form-element/

For this you also need to use elementor plugin and create a product page through elementor为此,您还需要使用 elementor 插件并通过 elementor 创建产品页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM