Last active
July 13, 2023 00:30
-
-
Save amdrew/40fcef36a7842d80f66c to your computer and use it in GitHub Desktop.
EDD 2.0 - Show discount field by default
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 | |
/** | |
* Unhook default EDD discount field | |
*/ | |
remove_action( 'edd_checkout_form_top', 'edd_discount_field', -1 ); | |
/** | |
* Add our own callback for the discount field, keeping the same CSS as before | |
*/ | |
function sumobi_edd_discount_field() { | |
if( isset( $_GET['payment-mode'] ) && edd_is_ajax_disabled() ) { | |
return; // Only show before a payment method has been selected if ajax is disabled | |
} | |
if ( edd_has_active_discounts() && edd_get_cart_total() ) : | |
$color = edd_get_option( 'checkout_color', 'blue' ); | |
$color = ( $color == 'inherit' ) ? '' : $color; | |
$style = edd_get_option( 'button_style', 'button' ); | |
?> | |
<fieldset id="edd_discount_code"> | |
<p id="edd-discount-code-wrap"> | |
<label class="edd-label" for="edd-discount"> | |
<?php _e( 'Discount', 'edd' ); ?> | |
<img src="<?php echo EDD_PLUGIN_URL; ?>assets/images/loading.gif" id="edd-discount-loader" style="display:none;"/> | |
</label> | |
<span class="edd-description"><?php _e( 'Enter a coupon code if you have one.', 'edd' ); ?></span> | |
<input class="edd-input" type="text" id="edd-discount" name="edd-discount" placeholder="<?php _e( 'Enter discount', 'edd' ); ?>"/> | |
<input type="submit" class="edd-apply-discount edd-submit button <?php echo $color . ' ' . $style; ?>" value="<?php echo _x( 'Apply', 'Apply discount at checkout', 'edd' ); ?>"/> | |
<span id="edd-discount-error-wrap" class="edd_errors" style="display:none;"></span> | |
</p> | |
</fieldset> | |
<?php | |
endif; | |
} | |
add_action( 'edd_checkout_form_top', 'sumobi_edd_discount_field', -1 ); | |
/** | |
* Sprinkle a little bit of Javascript to override edd-checkout-global.js and show our field again | |
*/ | |
function sumobi_edd_discount_field_js() { | |
?> | |
<script> | |
jQuery(document).ready(function($) { | |
$('#edd-discount-code-wrap').show(); | |
}); | |
</script> | |
<?php } | |
add_action( 'wp_footer', 'sumobi_edd_discount_field_js' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment