WordPress.org

Ready to get started?Download WordPress

Forums

Easy Digital Downloads
[resolved] Variations as dropdown instead of radio buttons? (12 posts)

  1. robotor
    Member
    Posted 9 months ago #

    Looking at using this plugin to replace wp-ecommerce (which hardly ever works.)

    Question: is there a way to change the Variations from displaying as radio buttons to a dropdown instead?

    I sell items in many colors, and radio buttons would take up too much space.

    https://wordpress.org/plugins/easy-digital-downloads/

  2. Pippin Williamson
    Pippin's Plugins and Plugin Reviewer
    Plugin Author

    Posted 9 months ago #

  3. robotor
    Member
    Posted 9 months ago #

    What are the instructions for integration of that snippet?

  4. Pippin Williamson
    Pippin's Plugins and Plugin Reviewer
    Plugin Author

    Posted 9 months ago #

    1. Create a new custom plugin using Pluginception: https://wordpress.org/plugins/pluginception/

    2. Copy and paste the snippet into the bottom of the new plugin you created in 1.

  5. robotor
    Member
    Posted 9 months ago #

    A few things:

    1) That snippet is missing a closing php tag
    2) If you paste it in, people will need to remove the opening php tag
    3) When I get it running, it does not replace the radio buttons, so each "add to cart" action adds the product to the cart twice.

  6. Pippin Williamson
    Pippin's Plugins and Plugin Reviewer
    Plugin Author

    Posted 9 months ago #

    1. The closing PHP tag is not required.

    2. That's fine, remove it.

    3. Can you show me?

  7. robotor
    Member
    Posted 9 months ago #

    tell me what you think... the plugin added the dropdowns, but the radio selectors remain.
    http://www.ianlabs.com/

  8. Pippin Williamson
    Pippin's Plugins and Plugin Reviewer
    Plugin Author

    Posted 9 months ago #

    Try changing remove_action( 'edd_purchase_link_top', 'edd_purchase_variable_pricing', 10, 1 ); to remove_action( 'edd_purchase_link_top', 'edd_purchase_variable_pricing', 10 );

  9. robotor
    Member
    Posted 9 months ago #

    No change... here's the entire plugin:

    <?php
    /*
    Plugin Name: download variation dropdowns
    Plugin URI:
    Description:
    Version:
    Author:
    Author URI:
    License:
    License URI:
    */
    
    /*
     * Convert variable prices from radio buttons to a dropdown
     */
    function shoestrap_edd_purchase_variable_pricing( $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><!--end .edd_price_options-->';
    	do_action( 'edd_after_price_options', $download_id );
    }
    add_action( 'edd_purchase_link_top', 'shoestrap_edd_purchase_variable_pricing', 10, 1 );
    remove_action( 'edd_purchase_link_top', 'edd_purchase_variable_pricing', 10 );
  10. Pippin Williamson
    Pippin's Plugins and Plugin Reviewer
    Plugin Author

    Posted 9 months ago #

    Here's a working version:

    <?php
    /*
    Plugin Name: download variation dropdowns
    Plugin URI:
    Description:
    Version:
    Author:
    Author URI:
    License:
    License URI:
    */
    function shoestrap_add_actions() {
    
    	remove_action( 'edd_purchase_link_top', 'edd_purchase_variable_pricing', 10 );
    	add_action( 'edd_purchase_link_top', 'shoestrap_edd_purchase_variable_pricing', 10, 1 );
    
    }
    add_action( 'plugins_loaded', 'shoestrap_add_actions' );
    
    function shoestrap_edd_purchase_variable_pricing( $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><!--end .edd_price_options-->';
    	do_action( 'edd_after_price_options', $download_id );
    }
  11. robotor
    Member
    Posted 9 months ago #

    That worked... Thank you!

  12. Pippin Williamson
    Pippin's Plugins and Plugin Reviewer
    Plugin Author

    Posted 9 months ago #

    Glad to hear it!

Reply

You must log in to post.

About this Plugin

About this Topic