Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1394086
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI'm learning to build a woocommerce+dokan website. When a store owner signs into my platform, they can enter a product they wish to sell. One of the options I want the store owner to describe about their product is its condition as either Never used, Lightly used, Used, or Heavily used.
I am adding a new product attribute "Condition" as shown in the following screenshot:
Now when I sign in as a store owner, I see the option to save the Condition field with this user interface located at the bottom of the product add/edit page:
I want to replace this interface with a more intuitive control such as a <select>
menu that offers the four possible condition options.
I'm not comfortable enough with WordPress best practices to do this. So I was about to do the following:
- Create a child theme so that I have a place to override the default HTML with some custom HTML.
- Write an SQL statement that reads Condition taxonomy/terms directly from the appropriate
wp_term*
tables and load terms into a phparray()
which I will use to echo a<select name="prod_condition">...</select>
element in the child theme. - For saving the product, create a custom plugin with this hook
add_action( 'dokan_store_profile_saved', 'save_condition_field', 15 );
. This hook fires AFTER a product has been saved. In my hook, I will read from$_POST['prod_condition']
, then save the value by creating an SQL statement that writes directly to thewp_terms_relationships
andwp_postmeta
tables.
Is that the proper approach to creating a custom UI for saving advance custom fields in a woocommerce+dokan setup? Are there native wordpress/woocommerce/dokan functions or tools I should be leveraging? For example, are there html variable naming conventions I can follow that will circumvent the need for me to write my own SQL create/update statements? Or certain wordpress functions that can easily create a drop down menu that becomes part of the wordpress CRUD process?
My approach seems very brute right now.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI'm learning to build a woocommerce+dokan website. When a store owner signs into my platform, they can enter a product they wish to sell. One of the options I want the store owner to describe about their product is its condition as either Never used, Lightly used, Used, or Heavily used.
I am adding a new product attribute "Condition" as shown in the following screenshot:
Now when I sign in as a store owner, I see the option to save the Condition field with this user interface located at the bottom of the product add/edit page:
I want to replace this interface with a more intuitive control such as a <select>
menu that offers the four possible condition options.
I'm not comfortable enough with WordPress best practices to do this. So I was about to do the following:
- Create a child theme so that I have a place to override the default HTML with some custom HTML.
- Write an SQL statement that reads Condition taxonomy/terms directly from the appropriate
wp_term*
tables and load terms into a phparray()
which I will use to echo a<select name="prod_condition">...</select>
element in the child theme. - For saving the product, create a custom plugin with this hook
add_action( 'dokan_store_profile_saved', 'save_condition_field', 15 );
. This hook fires AFTER a product has been saved. In my hook, I will read from$_POST['prod_condition']
, then save the value by creating an SQL statement that writes directly to thewp_terms_relationships
andwp_postmeta
tables.
Is that the proper approach to creating a custom UI for saving advance custom fields in a woocommerce+dokan setup? Are there native wordpress/woocommerce/dokan functions or tools I should be leveraging? For example, are there html variable naming conventions I can follow that will circumvent the need for me to write my own SQL create/update statements? Or certain wordpress functions that can easily create a drop down menu that becomes part of the wordpress CRUD process?
My approach seems very brute right now.
Share Improve this question edited May 8, 2019 at 7:00 LoicTheAztec 3,39117 silver badges24 bronze badges asked May 7, 2019 at 17:12 learningtechlearningtech 1971 silver badge14 bronze badges 2- That has nothing to do with advanced custom fields plugin… It's just the default product attributes UI on your screenshot... Here you have simply added a product attribute "Condition" with 4 terms: "Never used", "Lightly used", "Used" and Heavily used. – LoicTheAztec Commented May 8, 2019 at 4:17
- As interesting as this question is, 3rd party plugin dev support is offtopic here, this site is not the place to ask for WooCommerce dev help, contact their dev support routes, or communities instead. – Tom J Nowell ♦ Commented Jun 1, 2020 at 9:17
1 Answer
Reset to default 1Actually, this ended up being straight forward.
Displaying the drop down
I used this line to get the list of terms for my pa_condition
taxonomy:
$attr_condition = get_terms(
array(
'taxonomy' => 'pa_condition', //empty string(''), false, 0 don't work, and return empty array
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false, //can be 1, '1' too
));
And I used this to get the condition value for the current product (aka post)
$post_condition = get_the_terms($post_id,'pa_condition');
Then it was a simple matter of using a for loop to echo out all the options and setting the appropriate select option for the condition.
Saving the drop down
I first deleted the custom attributes control by making a child theme of the file plugins\dokan-pro\templates\products\product-variations.php
and then emptying it of all html content.
Then I made sure I named my select
menu and echoed the appropriate html variables in a convention that allows Wordpress to save values without any new backend code like this
<select name="attribute_values[0][0]" class="dokan-form-control">
<?php
$val = count($post_condition) > 0 ? $post_condition[0]->slug : "";
foreach($attr_condition as $item) {
$selected = $val == $item->slug ? ' selected' : '';
echo '<option value="'.$item->slug.'"'.$selected.'>'.$item->name.'</option>';
}
?>
</select>
<input type="hidden" name="attribute_names[0]" value="pa_condition" />
<input type="hidden" name="attribute_position[0]" value="0" />
<input type="hidden" name="attribute_is_taxonomy[0]" value="1" />
<input type="hidden" name="attribute_visibility[0]" value="1" />
These html variables will create the appropriate $_POST
schema to save custom attribute values from my new drop down menu.
本文标签: Approach for saving a product attribute values with a custom UI in a woocommercedokan set up
版权声明:本文标题:Approach for saving a product attribute values with a custom UI in a woocommerce+dokan set up 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744651922a2617734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论