Last active
October 7, 2016 16:07
-
-
Save SeanChDavis/9e0d0513b91adf8f4c5d to your computer and use it in GitHub Desktop.
Change EDD variable pricing radios to drop down select menu
This file contains hidden or 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 | |
| /* | |
| * Convert variable prices from radio buttons to a dropdown | |
| * | |
| * === JUST COPY THE CODE STARTING ON LINE 7 === | |
| */ | |
| function edd_purchase_variable_pricing_dropdown( $download_id ) { | |
| $variable_pricing = edd_has_variable_prices( $download_id ); | |
| if ( ! $variable_pricing ) | |
| return; | |
| $prices = apply_filters( 'edd_purchase_variable_prices', edd_get_variable_prices( $download_id ), $download_id ); | |
| $type = edd_single_price_option_mode( $download_id ) ? 'checkbox' : 'radio'; | |
| do_action( 'edd_before_price_options', $download_id ); | |
| echo '<div class="edd_price_options">'; | |
| if ( $prices ) { | |
| echo '<select name="edd_options[price_id][]">'; | |
| foreach ( $prices as $key => $price ) { | |
| printf( | |
| '<option for="%3$s" name="edd_options[price_id][]" id="%3$s" class="%4$s" value="%5$s" %7$s> %6$s</option>', | |
| checked( 0, $key, false ), | |
| $type, | |
| esc_attr( 'edd_price_option_' . $download_id . '_' . $key ), | |
| esc_attr( 'edd_price_option_' . $download_id ), | |
| esc_attr( $key ), | |
| esc_html( $price['name'] . ' - ' . edd_currency_filter( edd_format_amount( $price[ 'amount' ] ) ) ), | |
| selected( isset( $_GET['price_option'] ), $key, false ) | |
| ); | |
| do_action( 'edd_after_price_option', $key, $price, $download_id ); | |
| } | |
| echo '</select>'; | |
| } | |
| do_action( 'edd_after_price_options_list', $download_id, $prices, $type ); | |
| echo '</div>'; | |
| do_action( 'edd_after_price_options', $download_id ); | |
| } | |
| add_action( 'edd_purchase_link_top', 'edd_purchase_variable_pricing_dropdown', 10, 1 ); | |
| remove_action( 'edd_purchase_link_top', 'edd_purchase_variable_pricing', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow this is awesome and lightweight! However I have a couple problems:
This doesn't take default option on the variable price setting into account, and it changed the button text to the default versus using what is in the shortcode.
How hard would it be to fix those two bugs?