selected logic, with added sanitize_title

This commit is contained in:
Mike Jolley 2018-05-29 14:32:20 +01:00
parent 301e9339a9
commit 45d6c55f2a
1 changed files with 6 additions and 0 deletions

View File

@ -2767,6 +2767,12 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
'show_option_none' => __( 'Choose an option', 'woocommerce' ),
) );
// Get selected value.
if ( false === $args['selected'] && $args['attribute'] && $args['product'] instanceof WC_Product ) {
$selected_key = 'attribute_' . sanitize_title( $args['attribute'] );
$args['selected'] = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( urldecode( wp_unslash( $_REQUEST[ $selected_key ] ) ) ) : $args['product']->get_variation_default_attribute( $args['attribute'] ); // WPCS: input var ok, CSRF ok, sanitization ok.
}
$options = $args['options'];
$product = $args['product'];
$attribute = $args['attribute'];