WooCommerce Dropdown Empty
-
HI All
I am working on a custom theme for Elementor and have been creating my own custom add to cart widget, i have set up the simple product one with no problem and i have been trying to do a variable one.
everything works apart from the attributes dropdown, i know there is something i have missed, if anyone can help me where i have gone wrong this will help me a lot, i have been looking at this all day and looked on various sites and their code seems the same as mine but mine don’t work.
I have set up my variations and they seem to be showing on the product page, hwoever my drop down just says choose weight, then no options.
Here is my code, if anybody can have a look and see whats wrong.
$available_variations = $product->get_available_variations(); $attributes = $product->get_attributes(); $attribute_keys = array_keys( $attributes ); $variations_json = wp_json_encode( $available_variations ); $variations_attr = function_exists( 'wc_esc_json' ) ? wc_esc_json( $variations_json ) : _wp_specialchars( $variations_json, ENT_QUOTES, 'UTF-8', true ); <tbody> <?php $variations_arr = array(); foreach ( $attributes as $attribute_name => $options ) : ob_start(); ?> <tr> <td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td> <td class="value"> <?php $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name ); wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) ); echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : ''; ?> </td> </tr> <?php $variations_ob = ob_get_clean(); $variations_arr[wc_attribute_label($attribute_name)] = $variations_ob; endforeach; foreach ($variations_arr as $name => $ob) { echo str_ireplace('choose an option', 'Choose '.$name, $ob ); } ?> </tbody> </table>
Any help would be appreciated as i now have a headache trying to troubleshoot it all day.
The page I need help with: [log in to see the link]
- The topic ‘WooCommerce Dropdown Empty’ is closed to new replies.