i already have the template pages and functions for adding a variable product! I also have an edit page, where the frontend user can add attributes and then create variations. What i would like to do is force them to fill only a attribute (for example: size) when they go to the edit page.

This is how i am adding products:

wp_set_object_terms( $product_id, (int) $_POST['product_cat'], 'product_cat' );
        wp_set_object_terms( $product_id, 'variable', 'product_type' );
        wp_set_object_terms( $post_id, $avail_attributes, 'pa_size' );
$thedata = Array('pa_size'=>Array(
    'name'=>'pa_size',
    'value'=>'',
    'is_visible' => '1', 
    'is_variation' => '1',
    'is_taxonomy' => '1'
    ));
update_post_meta( $post_id,'_product_attributes',$thedata);
        update_post_meta( $product_id, '_regular_price', $price );
        update_post_meta( $product_id, '_sale_price', '' );
        update_post_meta( $product_id, '_price', $price );
        update_post_meta( $product_id, '_visibility', 'visible' );
        update_post_meta( $product_id, 'A0', 'pa_size' );
        do_action( 'dokan_new_product_added', $product_id, $post_data );

And this is on my attributes edit page they have:

    // Array of defined attribute taxonomies
$attribute_taxonomies = wc_get_attribute_taxonomies();
// Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set
$attributes = maybe_unserialize( get_post_meta( $thepostid, '_product_attributes', true ) );
$i = -1;
// var_dump($attributes, $attribute_taxonomies);
// Custom Attributes
if ( ! empty( $attributes ) ) {
    foreach ( $attributes as $attribute ) {
        // var_dump($attribute);
        if ( $attribute['is_taxonomy'] ) {
            $tax = get_taxonomy( $attribute['name'] );
            $attribute_name = $tax->labels->name;
            $options = wp_get_post_terms( $thepostid, $attribute['name'], array('fields' => 'names') );
        } else {
            $attribute_name = $attribute['name'];
            $options = array_map( 'trim', explode('|', $attribute['value'] ) );
        }

I’m quite new to all this wordpress functions, sorry for being unclear!

Read more here: Adding product attributes/variations from the frontend on woocommerce


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: