Created
January 16, 2018 18:31
-
-
Save raftaar1191/a7cea38b6cec8dc4c17d85156c015f7d to your computer and use it in GitHub Desktop.
Give Display Custom Amount in first Place when Form Display type is set as button
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 | |
/** | |
* Moves the custom amount to the beginning of the button. | |
* | |
* @param $output | |
* @param $form_id | |
*/ | |
function give_button_donations_custom_amount_first( $output, $form_id ) { | |
$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); | |
$display_style = give_get_meta( $form_id, '_give_display_style', true ); | |
$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); | |
$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); | |
if ( empty( $custom_amount_text ) ) { | |
$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' ); | |
} | |
if ( 'buttons' === $display_style ) { | |
$output = '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">'; | |
//Custom Amount. | |
if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) { | |
$output .= '<li>'; | |
$output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">'; | |
$output .= $custom_amount_text; | |
$output .= '</button>'; | |
$output .= '</li>'; | |
} | |
foreach ( $prices as $price ) { | |
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price ); | |
$level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'give-default-level' : '' ), $form_id, $price ); | |
$output .= '<li>'; | |
$output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">'; | |
$output .= $level_text; | |
$output .= '</button>'; | |
$output .= '</li>'; | |
} | |
$output .= '</ul>'; | |
} | |
echo $output; | |
} | |
add_filter( 'give_form_level_output', 'give_button_donations_custom_amount_first', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Give Support Ticket: https://wordpress.org/support/topic/custom-amount-make-it-first-option-in-dropdown/#post-9867960