WordPress.org

Support

Support » Plugins and Hacks » Variations are not Working

Variations are not Working

  • I’m trying to customize a page where it reads an array of attributes from the _GET function and create the required pages and postmeta instead of having user entering the CMS.

    I can see the fields are entered in the database but when it comes to viewing it in the variations it does not show anything nor does the single product page.

    Please help, I just need this final bit to complete my assignment.

    Many thanks in advance!

    $data['attributes'] = $_GET['att'];
    $data['page_id'] = $_GET['pageid'];
    $data['pa'] = $_GET['pa'];
    wp_set_object_terms( intval($data['page_id']), $data['attributes'], $data['pa'] );
    $thedata = Array('pa_size'=>Array(
    	'name'=>$data['pa'],
    	'value'=> $data['attributes'],
    	'is_visible' => '1',
    	'is_variation' => '1',
    	'is_taxonomy' => '1'
    	));
    update_post_meta( $data['page_id'],'_product_attributes',$thedata);
    $counter = 0;
    $last = $wpdb->get_row("SHOW TABLE STATUS LIKE 'wp_posts'");
    $lastid = $last->Auto_increment;
    
    foreach($data['attributes'] as $item)
    {
    
    	$comment_status = "open";
    	$ping_status = "open";
    	if($counter == 0)
    	{
    		$post_name = "product-".$data['page_id']."-variation";
    		$guid = "http://www.hkstylish.com/?product_variation=product-".$data['page_id']."-variation";
    	}
    	else
    	{
    		$temp_counter = $counter + 1;
    		$post_name = "product-".$data['page_id']."-variation-".$temp_counter;
    		$guid = "http://www.hkstylish.com/?product_variation=product-".$data['page_id']."-variation-".$temp_counter;
    	}
    	$post_parent = $data['page_id'];
    	$menu_order = $counter;
    	$post_type = "product_variation";
    	$get_post_name = $wpdb->get_results('SELECT * FROM <code>wp_posts</code> WHERE <code>ID</code> = "'.$data['page_id'].'"');
    	$post_name1 = $get_post_name[0]->post_title;
    	$variation = array(
    		'post_title' 	=> "Variation #".$lastid." of ".$post_name1,
    		'post_content' 	=> '',
    		'post_status' 	=> "published",
    		'post_author' 	=> get_current_user_id(),
    		'post_parent' 	=> $data['page_id'],
    		'post_type' 	=> 'product_variation',
    		'menu_order' 	=> $counter,
    		'post_name' 	=> $post_name,
    		'guid'			=> $guid
    	);
    	$variation_id = wp_insert_post( $variation );
    	do_action( 'woocommerce_create_product_variation', $variation_id );
    	update_post_meta( $variation_id, '_stock', $_GET['stock'][$counter] );
    	update_post_meta( $variation_id, '_sku', "" );
    	update_post_meta( $variation_id, '_weight', "" );
    	update_post_meta( $variation_id, 'length', "" );
    	update_post_meta( $variation_id, '_width', "" );
    	update_post_meta( $variation_id, '_height', "" );
    	update_post_meta( $variation_id, '_stock', $_GET['stock'][$counter] );
    	update_post_meta( $variation_id, '_thumbnail_id', 0 );
    	update_post_meta( $variation_id, '_virtual', "no" );
    	update_post_meta( $variation_id, '_downloadable', "no" );
    	update_post_meta( $variation_id, '_regular_price', 20 );
    	update_post_meta( $variation_id, '_sale_price_dates_from', "" );
    	update_post_meta( $variation_id, '_sale_price_dates_to', "" );
    	update_post_meta( $variation_id, '_price', 20 );
    	update_post_meta( $variation_id, '_tax_class', "" );
    	update_post_meta( $variation_id, '_download_limit', "" );
    	update_post_meta( $variation_id, '_download_expiry', "" );
    	update_post_meta( $variation_id, '_file_paths', "" );
    	do_action( 'woocommerce_save_product_variation', $variation_id );
    	$counter++;
    	$lastid++;
    }
    // Update parent if variable so price sorting works and stays in sync with the cheapest child
    $post_parent = $data['page_id'];
    
    $children = get_posts( array(
    	'post_parent' 	=> $post_parent,
    	'post_type' 	=> 'product_variation',
    	'post_status'	=> 'publish'
    ) );

    http://wordpress.org/extend/plugins/woocommerce/

  • The topic ‘Variations are not Working’ is closed to new replies.