Created
July 9, 2020 19:00
-
-
Save gerrgg/c4c88c03fa6b00197da2881e4871e74a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wcfbt_get_variation_dropdown( $product_id ){ | |
/** | |
* Create a inline dropdown for selecting available product variations | |
*/ | |
$product = wc_get_product( $product_id ); | |
// if product exists and has available variations to list. | |
if( $product && ! empty( $product->get_variation_attributes() ) ){ | |
foreach ( $product->get_variation_attributes() as $attribute_name => $options ) : ?> | |
<?php | |
echo '<strong>' . wc_attribute_label( $attribute_name ) . ': </strong>'; | |
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( urldecode( $_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 ) ); | |
?> | |
<?php endforeach; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment