Hello,
the value of the taxonomy terms are empty After form submit.
Thanks a lot for the help!
$value=$_POST["pa_condition"];
$taxonomies = get_taxonomies();
foreach ( $taxonomies as $tax_type_key => $taxonomy ) {
if ( $term_object = get_term_by( 'slug', $value , $taxonomy ) ) {
break;
}
}
$term_id = htmlspecialchars( stripslashes( $term_object->taxonomy) );
$term_taxonomy_ids =wp_set_object_terms( $post_id, $value, '_product_attributes' ,true);
$product_attributes= array (
'name' => $term_id, // set attribute name
'value' => $value, // set attribute value
'position' => 1,
'is_visible' => 1,
'is_variation' => 1,
'is_taxonomy' => 1
);
if(count($product_attributes) > 0)
{
update_post_meta($post_id, '_product_attributes', $product_attributes);
}
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - Toolset Forms do not support product attributes for now (You can add to forms but attribues will not get saved to database). You can see its already mentioned with our Docs:
=> https://toolset.com/documentation/user-guides/creating-woocommerce-products-using-cred-forms/#which-product-fields-you-can-use-in-toolset-forms
if you want to publish products and set product attributes this needs custom code. The following link may help you:
=> hidden link
Hi Minesh,
Yes I want to publish products and set product attributes but ATTRIBUTE_VALUE
he save an empty value (screenshot)
add_action( 'dokan_product_updated', 'x_add_fields_save' ,10, 2);
function x_add_fields_save( $post_id ){
$term_id = htmlspecialchars( stripslashes( $taxonomy) );
$term_taxonomy_ids =wp_set_object_terms( $post_id, $value, '_product_attributes' ,true);
$product_attributes= array (
'name' => $term_id, // set attribute name
'value' => $value, // set attribute value
'position' => 1,
'is_visible' => 1,
'is_variation' => 1,
'is_taxonomy' => 1
);
if(count($product_attributes) > 0)
{
update_post_meta($post_id, '_product_attributes', $product_attributes);
}
}
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Well - as I already informed you that this is a custom code which is eventually beyond the scope of our support policy as Toolset does not offer this feature natively.
If custom programming is something you are comfortable doing you may ask the help of a developer who is able to write PHP using the Forms API. I suggest for our any custom programming need, please feel free to contact our certified partners:
=> https://toolset.com/contractors/
I found the solution Thank you.
term_taxonomy_ids =wp_set_object_terms( $post_id, $value, $term_id ,true);
$product_attributes[$i] = array (
'name' => $term_id, // set attribute name
'value' => $value, //
'position' => 1,
'is_visible' => 1,
'is_variation' => 1,
'is_taxonomy' => 1
);
My issue is resolved now. Thank you!