woocommerce variations

后端 未结 5 861
再見小時候
再見小時候 2020-12-14 08:14

I am creating a woocommerce theme and I have product variations i.e. size which is displayed on product details page but problem is that I want to get all variations in my c

5条回答
  •  青春惊慌失措
    2020-12-14 08:39

    Try this,

    name;
    $t_shirt_price[] = $t_shirt_sizes_array[$scnt]->slug;
    $t_shirt_size_id[] = $t_shirt_sizes_array[$scnt]->term_id;
    }
    $cnt = 1;
    for($i = 0; $i < count($t_shirt_size); $i++){
    $name_size = $t_shirt_size[$i];
    
    $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = 
    '".$t_shirt_size[$i]."'" );
    $term_slug = ( !empty( $result ) ) ? $result[0] : $term;
     $query = "SELECT postmeta.post_id AS product_id
        FROM {$wpdb->prefix}postmeta AS postmeta
    LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )
        WHERE postmeta.meta_key LIKE 'attribute_%'
            AND postmeta.meta_value = '$term_slug'
            AND products.post_parent = ".$_GET['pr_id'];    
    $variation_id = $wpdb->get_col( $query );
    
    $parent = wp_get_post_parent_id( $variation_id[0] );
    if ( $parent > 0 ) {                    
        echo $name_size;
        $_product = new WC_Product_Variation( $variation_id[0] );
        echo $_product->get_price();
    }
    $price = $t_shirt_price[$i];
    $cnt++;
    }
    ?>
    

提交回复
热议问题