Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_agree_to_terms_js
  • edd_can_checkout
  • edd_checkout_button_next
  • edd_checkout_button_purchase
  • edd_checkout_final_total
  • edd_checkout_form
  • edd_checkout_hidden_fields
  • edd_checkout_submit
  • edd_default_cc_address_fields
  • edd_discount_field
  • edd_get_cc_form
  • edd_get_login_fields
  • edd_get_register_fields
  • edd_payment_mode_select
  • edd_show_local_tax_opt_in
  • edd_show_payment_icons
  • edd_show_purchase_form
  • edd_terms_agreement
  • edd_user_info_fields
  1 <?php
  2 /**
  3  * Checkout Template
  4  *
  5  * @package     EDD
  6  * @subpackage  Checkout
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10 */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Get Checkout Form
 17  *
 18  * @since 1.0
 19  * @global $edd_options Array of all the EDD options
 20  * @global $user_ID ID of current logged in user
 21  * @global $post Current Post Object
 22  * @return string
 23  */
 24 function edd_checkout_form() {
 25     global $edd_options, $user_ID, $post;
 26     ob_start();
 27         if ( edd_get_cart_contents() ) :
 28             edd_checkout_cart();
 29         ?>
 30             <div id="edd_checkout_form_wrap" class="edd_clearfix">
 31                 <?php
 32                 do_action( 'edd_checkout_form_top' );
 33 
 34                 if ( edd_show_gateways() ) {
 35                     do_action( 'edd_payment_payment_mode_select'  );
 36                 } else {
 37                     do_action( 'edd_purchase_form' );
 38                 }
 39 
 40                 do_action( 'edd_checkout_form_bottom' )
 41                 ?>
 42             </div><!--end #edd_checkout_form_wrap-->
 43         <?php
 44         else:
 45             do_action( 'edd_empty_cart' );
 46         endif;
 47     return ob_get_clean();
 48 }
 49 
 50 /**
 51  * Renders the Purchase Form, hooks are provided to add to the purchase form.
 52  * The default Purchase Form rendered deisplays a list of the enabled payment
 53  * gateways, a user registration form (if enable) and a credit card info form
 54  * if credit cards are enabled
 55  *
 56  * @since 1.4
 57  * @global $edd_options Array of all the EDD options
 58  * @return string
 59  */
 60 function edd_show_purchase_form() {
 61     global $edd_options;
 62 
 63     $payment_mode = edd_get_chosen_gateway();
 64     $form_action = esc_url( edd_get_checkout_uri('payment-mode=' . $payment_mode) );
 65 
 66     do_action( 'edd_before_purchase_form' ); ?>
 67 
 68     <form id="edd_purchase_form" action="<?php echo $form_action; ?>" method="POST">
 69         <?php
 70         do_action( 'edd_purchase_form_top' );
 71 
 72         if ( edd_can_checkout() ) { ?>
 73             <?php if( isset( $edd_options['show_register_form'] ) && !is_user_logged_in() && !isset( $_GET['login'] ) ) { ?>
 74                 <div id="edd_checkout_login_register"><?php do_action( 'edd_purchase_form_register_fields' ); ?></div>
 75             <?php } elseif( isset( $edd_options['show_register_form'] ) && !is_user_logged_in() && isset( $_GET['login'] ) ) { ?>
 76                 <div id="edd_checkout_login_register"><?php do_action( 'edd_purchase_form_login_fields' ); ?></div>
 77             <?php } ?>
 78 
 79             <?php if( ( !isset( $_GET['login'] ) && is_user_logged_in() ) || !isset( $edd_options['show_register_form'] ) ) {
 80                 do_action( 'edd_purchase_form_after_user_info' );
 81             }
 82 
 83             do_action( 'edd_purchase_form_before_cc_form' );
 84 
 85             // Load the credit card form and allow gateways to load their own if they wish
 86             if ( has_action( 'edd_' . $payment_mode . '_cc_form' ) ) {
 87                 do_action( 'edd_' . $payment_mode . '_cc_form' );
 88             } else {
 89                 do_action( 'edd_cc_form' );
 90             }
 91 
 92             do_action( 'edd_purchase_form_after_cc_form' );
 93         } else {
 94             // Can't checkout
 95             do_action( 'edd_purchase_form_no_access' );
 96         }
 97 
 98         do_action( 'edd_purchase_form_bottom' );
 99         ?>
100     </form>
101     <?php
102     do_action( 'edd_after_purchase_form' );
103 }
104 add_action( 'edd_purchase_form', 'edd_show_purchase_form' );
105 
106 /**
107  * Shows the User Info fields in the Personal Info box, more fields can be added
108  * via the hooks provided.
109  *
110  * @since 1.3.3
111  * @return void
112  */
113 function edd_user_info_fields() {
114     if ( is_user_logged_in() ) :
115         $user_data = get_userdata( get_current_user_id() );
116     endif;
117     ?>
118     <fieldset id="edd_checkout_user_info">
119         <legend><?php echo apply_filters( 'edd_checkout_personal_info_text', __( 'Personal Info', 'edd' ) ); ?></legend>
120         <?php do_action( 'edd_purchase_form_before_email' ); ?>
121         <p id="edd-email-wrap">
122             <label class="edd-label" for="edd-email"><?php _e( 'Email Address', 'edd' ); ?></label>
123             <span class="edd-description"><?php _e( 'We will send the purchase receipt to this address.', 'edd' ); ?></span>
124             <input class="edd-input required" type="email" name="edd_email" placeholder="<?php _e( 'Email address', 'edd' ); ?>" id="edd-email" value="<?php echo is_user_logged_in() ? $user_data->user_email : ''; ?>"/>
125         </p>
126         <?php do_action( 'edd_purchase_form_after_email' ); ?>
127         <p id="edd-first-name-wrap">
128             <label class="edd-label" for="edd-first"><?php _e( 'First Name', 'edd' ); ?></label>
129             <span class="edd-description"><?php _e( 'We will use this to personalize your account experience.', 'edd' ); ?></span>
130             <input class="edd-input required" type="text" name="edd_first" placeholder="<?php _e( 'First Name', 'edd' ); ?>" id="edd-first" value="<?php echo is_user_logged_in() ? $user_data->first_name : ''; ?>"/>
131         </p>
132         <p id="edd-last-name-wrap">
133             <label class="edd-label" for="edd-last"><?php _e( 'Last Name', 'edd' ); ?></label>
134             <span class="edd-description"><?php _e( 'We will use this as well to personalize your account experience.', 'edd' ); ?></span>
135             <input class="edd-input" type="text" name="edd_last" id="edd-last" placeholder="<?php _e( 'Last name', 'edd' ); ?>" value="<?php echo is_user_logged_in() ? $user_data->last_name : ''; ?>"/>
136         </p>
137         <?php do_action( 'edd_purchase_form_user_info' ); ?>
138     </fieldset>
139     <?php
140 }
141 add_action( 'edd_purchase_form_after_user_info', 'edd_user_info_fields' );
142 
143 /**
144  * Renders the credit card info form.
145  *
146  * @since 1.0
147  * @return void
148  */
149 function edd_get_cc_form() {
150     ob_start(); ?>
151 
152     <?php do_action( 'edd_before_cc_fields' ); ?>
153 
154     <fieldset id="edd_cc_fields" class="edd-do-validate">
155         <legend><?php _e( 'Credit Card Info', 'edd' ); ?></legend>
156         <?php if( is_ssl() ) : ?>
157             <div id="edd_secure_site_wrapper">
158                 <span class="padlock"></span>
159                 <span><?php _e( 'This is a secure SSL encrypted payment.', 'edd' ); ?></span>
160             </div>
161         <?php endif; ?>
162         <p id="edd-card-number-wrap">
163             <label class="edd-label"><?php _e( 'Card Number', 'edd' ); ?><span class="card-type"></span></label>
164             <span class="edd-description"><?php _e( 'The (typically) 16 digits on the front of your credit card.', 'edd' ); ?></span>
165             <input type="text" autocomplete="off" name="card_number" class="card-number edd-input required" placeholder="<?php _e( 'Card number', 'edd' ); ?>" />
166         </p>
167         <p id="edd-card-cvc-wrap">
168             <label class="edd-label"><?php _e( 'CVC', 'edd' ); ?></label>
169             <span class="edd-description"><?php _e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'edd' ); ?></span>
170             <input type="text" size="4" autocomplete="off" name="card_cvc" class="card-cvc edd-input required" placeholder="<?php _e( 'Security code', 'edd' ); ?>" />
171         </p>
172         <p id="edd-card-name-wrap">
173             <label class="edd-label"><?php _e( 'Name on the Card', 'edd' ); ?></label>
174             <span class="edd-description"><?php _e( 'The name printed on the front of your credit card.', 'edd' ); ?></span>
175             <input type="text" autocomplete="off" name="card_name" class="card-name edd-input required" placeholder="<?php _e( 'Card name', 'edd' ); ?>" />
176         </p>
177         <?php do_action( 'edd_before_cc_expiration' ); ?>
178         <p class="card-expiration">
179             <label class="edd-label"><?php _e( 'Expiration (MM/YY)', 'edd' ); ?></label>
180             <span class="edd-description"><?php _e( 'The date your credit card expires, typically on the front of the card.', 'edd' ); ?></span>
181             <select name="card_exp_month" class="card-expiry-month edd-select edd-select-small required">
182                 <?php for( $i = 1; $i <= 12; $i++ ) { echo '<option value="' . $i . '">' . sprintf ('%02d', $i ) . '</option>'; } ?>
183             </select>
184             <span class="exp-divider"> / </span>
185             <select name="card_exp_year" class="card-expiry-year edd-select edd-select-small required">
186                 <?php for( $i = date('Y'); $i <= date('Y') + 10; $i++ ) { echo '<option value="' . $i . '">' . substr( $i, 2 ) . '</option>'; } ?>
187             </select>
188         </p>
189         <?php do_action( 'edd_after_cc_expiration' ); ?>
190 
191     </fieldset>
192     <?php
193     do_action( 'edd_after_cc_fields' );
194 
195     echo ob_get_clean();
196 }
197 add_action( 'edd_cc_form', 'edd_get_cc_form' );
198 
199 /**
200  * Outputs the default credit card address fields
201  *
202  * @since 1.0
203  * @return void
204  */
205 function edd_default_cc_address_fields() {
206     ob_start(); ?>
207     <fieldset id="edd_cc_address" class="cc-address">
208         <?php do_action( 'edd_cc_billing_top' ); ?>
209         <p id="edd-card-address-wrap">
210             <label class="edd-label"><?php _e( 'Billing Address', 'edd' ); ?></label>
211             <span class="edd-description"><?php _e( 'The primary billing address for your credit card.', 'edd' ); ?></span>
212             <input type="text" name="card_address" class="card-address edd-input required" placeholder="<?php _e( 'Address line 1', 'edd' ); ?>"/>
213         </p>
214         <p id="edd-card-address-2-wrap">
215             <label class="edd-label"><?php _e( 'Billing Address Line 2 (optional)', 'edd' ); ?></label>
216             <span class="edd-description"><?php _e( 'The suite, apt no, PO box, etc, associated with your billing address.', 'edd' ); ?></span>
217             <input type="text" name="card_address_2" class="card-address-2 edd-input" placeholder="<?php _e( 'Address line 2', 'edd' ); ?>"/>
218         </p>
219         <p id="edd-card-city-wrap">
220             <label class="edd-label"><?php _e( 'Billing City', 'edd' ); ?></label>
221             <span class="edd-description"><?php _e( 'The city for your billing address.', 'edd' ); ?></span>
222             <input type="text" name="card_city" class="card-city edd-input required" placeholder="<?php _e( 'City', 'edd' ); ?>"/>
223         </p>
224         <p id="edd-card-country-wrap">
225             <label class="edd-label"><?php _e( 'Billing Country', 'edd' ); ?></label>
226             <span class="edd-description"><?php _e( 'The country for your billing address.', 'edd' ); ?></span>
227             <select name="billing_country" class="billing-country edd-select required">
228                 <?php
229                 $countries = edd_get_country_list();
230                 foreach( $countries as $country_code => $country ) {
231                   echo '<option value="' . $country_code . '">' . $country . '</option>';
232                 }
233                 ?>
234             </select>
235         </p>
236         <p id="edd-card-state-wrap">
237             <label class="edd-label"><?php _e( 'Billing State / Province', 'edd' ); ?></label>
238             <span class="edd-description"><?php _e( 'The state or province for your billing address.', 'edd' ); ?></span>
239             <input type="text" size="6" name="card_state_other" id="card_state_other" class="card-state edd-input" placeholder="<?php _e( 'State / Province', 'edd' ); ?>" style="display:none;"/>
240             <select name="card_state_us" id="card_state_us" class="card-state edd-select required">
241                 <?php
242                     $states = edd_get_states_list();
243                     foreach( $states as $state_code => $state ) {
244                         echo '<option value="' . $state_code . '">' . $state . '</option>';
245                     }
246                 ?>
247             </select>
248             <select name="card_state_ca" id="card_state_ca" class="card-state edd-select required" style="display: none;">
249                 <?php
250                     $provinces = edd_get_provinces_list();
251                     foreach( $provinces as $province_code => $province ) {
252                         echo '<option value="' . $province_code . '">' . $province . '</option>';
253                     }
254                 ?>
255             </select>
256         </p>
257         <p id="edd-card-zip-wrap">
258             <label class="edd-label"><?php _e( 'Billing Zip / Postal Code', 'edd' ); ?></label>
259             <span class="edd-description"><?php _e( 'The zip or postal code for your billing address.', 'edd' ); ?></span>
260             <input type="text" size="4" name="card_zip" class="card-zip edd-input required" placeholder="<?php _e( 'Zip / Postal code', 'edd' ); ?>"/>
261         </p>
262         <?php do_action( 'edd_cc_billing_bottom' ); ?>
263     </fieldset>
264     <?php
265     echo ob_get_clean();
266 }
267 add_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields' );
268 
269 /**
270  * Renders the user registration fields. If the user is logged in, a login
271  * form is displayed other a registration form is provided for the user to
272  * create an account.
273  *
274  * @since 1.0
275  * @return string
276  */
277 function edd_get_register_fields() {
278     global $edd_options;
279     global $user_ID;
280 
281     if ( is_user_logged_in() )
282     $user_data = get_userdata( $user_ID );
283 
284     ob_start(); ?>
285     <fieldset id="edd_register_fields">
286         <p id="edd-login-account-wrap"><?php _e( 'Already have an account?', 'edd' ); ?> <a href="<?php echo add_query_arg('login', 1); ?>" class="edd_checkout_register_login" data-action="checkout_login"><?php _e( 'Login', 'edd' ); ?></a></p>
287         <p id="edd-user-email-wrap">
288             <label for="edd-email"><?php _e( 'Email', 'edd' ); ?></label>
289             <span class="edd-description"><?php _e( 'We will send the purchase receipt to this address.', 'edd' ); ?></span>
290             <input name="edd_email" id="edd-email" class="required edd-input" type="email" placeholder="<?php _e( 'Email', 'edd' ); ?>" title="<?php _e( 'Email', 'edd' ); ?>"/>
291         </p>
292         <p id="edd-user-first-name-wrap">
293             <label class="edd-label" for="edd-first"><?php _e( 'First Name', 'edd' ); ?></label>
294             <span class="edd-description"><?php _e( 'We will use this to personalize your account experience.', 'edd' ); ?></span>
295             <input class="edd-input required" type="text" name="edd_first" placeholder="<?php _e( 'First Name', 'edd' ); ?>" id="edd-first" value="<?php echo is_user_logged_in() ? $user_data->user_firstname : ''; ?>"/>
296         </p>
297         <p id="edd-user-last-name-wrap">
298             <label class="edd-label" for="edd-last"><?php _e( 'Last Name', 'edd' ); ?></label>
299             <span class="edd-description"><?php _e( 'We will use this as well to personalize your account experience.', 'edd' ); ?></span>
300             <input class="edd-input" type="text" name="edd_last" id="edd-last" placeholder="<?php _e( 'Last name', 'edd' ); ?>" value="<?php echo is_user_logged_in() ? $user_data->user_lastname : ''; ?>"/>
301         </p>
302         <fieldset id="edd_register_account_fields">
303             <legend><?php _e( 'Create an account', 'edd' ); if( !edd_no_guest_checkout() ) { echo ' ' . __( '(optional)', 'edd' ); } ?></legend>
304             <?php do_action('edd_register_account_fields_before'); ?>
305             <p id="edd-user-login-wrap">
306                 <label for="edd_user_login"><?php _e( 'Username', 'edd' ); ?></label>
307                 <span class="edd-description"><?php _e( 'The username you will use to log into your account.', 'edd' ); ?></span>
308                 <input name="edd_user_login" id="edd_user_login" class="<?php if(edd_no_guest_checkout()) { echo 'required '; } ?>edd-input" type="text" placeholder="<?php _e( 'Username', 'edd' ); ?>" title="<?php _e( 'Username', 'edd' ); ?>"/>
309             </p>
310             <p id="edd-user-pass-wrap">
311                 <label for="password"><?php _e( 'Password', 'edd' ); ?></label>
312                 <span class="edd-description"><?php _e( 'The password used to access your account.', 'edd' ); ?></span>
313                 <input name="edd_user_pass" id="edd_user_pass" class="<?php if(edd_no_guest_checkout()) { echo 'required '; } ?>edd-input" placeholder="<?php _e( 'Password', 'edd' ); ?>" type="password"/>
314             </p>
315             <p id="edd-user-pass-confirm-wrap" class="edd_register_password">
316                 <label for="password_again"><?php _e( 'Password Again', 'edd' ); ?></label>
317                 <span class="edd-description"><?php _e( 'Confirm your password.', 'edd' ); ?></span>
318                 <input name="edd_user_pass_confirm" id="edd_user_pass_confirm" class="<?php if(edd_no_guest_checkout()) { echo 'required '; } ?>edd-input" placeholder="<?php _e( 'Confirm password', 'edd' ); ?>" type="password"/>
319             </p>
320             <?php do_action( 'edd_register_account_fields_after' ); ?>
321         </fieldset>
322         <input type="hidden" name="edd-purchase-var" value="needs-to-register"/>
323 
324         <?php do_action( 'edd_purchase_form_user_info' ); ?>
325     </fieldset>
326     <?php
327     echo ob_get_clean();
328 }
329 add_action( 'edd_purchase_form_register_fields', 'edd_get_register_fields' );
330 
331 /**
332  * Gets the login fields for the login form on the checkout. This function hooks
333  * on the edd_purchase_form_login_fields to display the login form if a user already
334  * had an account. 
335  *
336  * @since 1.0
337  * @return string
338  */
339 function edd_get_login_fields() {
340     ob_start(); ?>
341         <fieldset id="edd_login_fields">
342             <legend><?php _e( 'Login to your account', 'edd' ); ?></legend>
343             <?php do_action('edd_checkout_login_fields_before'); ?>
344             <p id="edd-user-login-wrap">
345                 <label class="edd-label" for="edd-username"><?php _e( 'Username', 'edd' ); ?></label>
346                 <input class="<?php if(edd_no_guest_checkout()) { echo 'required '; } ?>edd-input" type="text" name="edd_user_login" id="edd_user_login" value="" placeholder="<?php _e( 'Your username', 'edd' ); ?>"/>
347             </p>
348             <p id="edd-user-pass-wrap" class="edd_login_password">
349                 <label class="edd-label" for="edd-password"><?php _e( 'Password', 'edd' ); ?></label>
350                 <input class="<?php if(edd_no_guest_checkout()) { echo 'required '; } ?>edd-input" type="password" name="edd_user_pass" id="edd_user_pass" placeholder="<?php _e( 'Your password', 'edd' ); ?>"/>
351                 <input type="hidden" name="edd-purchase-var" value="needs-to-login"/>
352             </p>
353             <?php do_action('edd_checkout_login_fields_after'); ?>
354         </fieldset><!--end #edd_login_fields-->
355         <p id="edd-new-account-wrap">
356             <?php _e( 'Need to create an account?', 'edd' ); ?>
357             <a href="<?php echo remove_query_arg('login'); ?>" class="edd_checkout_register_login" data-action="checkout_register">
358                 <?php _e( 'Register', 'edd' ); if(!edd_no_guest_checkout()) { echo ' ' . __( 'or checkout as a guest.', 'edd' ); } ?>
359             </a>
360         </p>
361     <?php
362     echo ob_get_clean();
363 }
364 add_action( 'edd_purchase_form_login_fields', 'edd_get_login_fields' );
365 
366 /**
367  * Renders the payment mode form by getting all the enabled payment gateways and
368  * outputting them as radio buttons for the user to choose the payment gateway. If
369  * a default payment gateway has been chosen from the EDD Settings, it will be
370  * automatically selected.
371  *
372  * @since 1.2.2
373  * @return void
374  */
375 function edd_payment_mode_select() {
376     $gateways = edd_get_enabled_payment_gateways();
377     $page_URL = edd_get_current_page_url();
378     do_action('edd_payment_mode_top'); ?>
379     <form id="edd_payment_mode" action="<?php echo $page_URL; ?>" method="GET">
380         <fieldset id="edd_payment_mode_select">
381             <?php do_action('edd_payment_mode_before_gateways'); ?>
382 
383             <p id="edd-payment-mode-wrap">
384                 <span class="edd-payment-mode-label"><?php _e( 'Select Payment Method', 'edd' ); ?></span><br/>
385                 <?php
386                 foreach ( $gateways as $gateway_id => $gateway ) :
387                     $checked = checked( $gateway_id, edd_get_default_gateway(), false );
388                     echo '<label for="edd-gateway-' . esc_attr( $gateway_id ) . '" class="edd-gateway-option" id="edd-gateway-option-' . esc_attr( $gateway_id ) . '">';
389                         echo '<input type="radio" name="payment-mode" class="edd-gateway" id="edd-gateway-' . esc_attr( $gateway_id ) . '" value="' . esc_attr( $gateway_id ) . '"' . $checked . '>' . esc_html( $gateway['checkout_label'] ) . '</option>';
390                     echo '</label>';
391                 endforeach;
392                 ?>
393             </p>
394 
395             <?php do_action('edd_payment_mode_after_gateways'); ?>
396         </fieldset>
397         <fieldset id="edd_payment_mode_submit" class="edd-no-js">
398             <p id="edd-next-submit-wrap">
399                 <?php echo edd_checkout_button_next(); ?>
400             </p>
401         </fieldset>
402     </form>
403     <div id="edd_purchase_form_wrap"></div><!-- the checkout fields are loaded into this-->
404     <?php do_action('edd_payment_mode_bottom');
405 }
406 add_action( 'edd_payment_payment_mode_select', 'edd_payment_mode_select' );
407 
408 /**
409  * Renders the Discount Code field which allows users to enter a discount code.
410  * This field is only displayed if there are any active discounts on the site else
411  * it's not displayed.
412  *
413  * @since 1.2.2
414  * @return void
415 */
416 function edd_discount_field() {
417     if ( edd_has_active_discounts() && ! edd_cart_has_discounts() ) {
418     ?>
419     <fieldset id="edd_discount_code">
420         <p id="edd-discount-code-wrap">
421             <label class="edd-label" for="edd-discount">
422                 <?php _e( 'Discount', 'edd' ); ?>
423                 <img src="<?php echo EDD_PLUGIN_URL; ?>assets/images/loading.gif" id="edd-discount-loader" style="display:none;"/>
424             </label>
425             <span class="edd-description"><?php _e( 'Enter a coupon code if you have one.', 'edd' ); ?></span>
426             <input class="edd-input" type="text" id="edd-discount" name="edd-discount" placeholder="<?php _e( 'Enter discount', 'edd' ); ?>"/>
427         </p>
428     </fieldset>
429     <?php
430     }
431 }
432 add_action( 'edd_purchase_form_before_cc_form', 'edd_discount_field' );
433 
434 /**
435  * Renders the Checkout Agree to Terms, this displays a checkbox for users to
436  * agree the T&Cs set in the EDD Settings. This is only displayed if T&Cs are
437  * set in the EDD Settigs.
438  *
439  * @since 1.3.2
440  * @global $edd_options Array of all the EDD Options
441  * @return void
442  */
443 function edd_terms_agreement() {
444     global $edd_options;
445     if ( isset( $edd_options['show_agree_to_terms'] ) ) {
446 ?>
447         <fieldset id="edd_terms_agreement">
448             <p id="edd-terms-wrap">
449                 <div id="edd_terms" style="display:none;">
450                     <?php
451                         do_action( 'edd_before_terms' );
452                         echo wpautop( $edd_options['agree_text'] );
453                         do_action( 'edd_after_terms' );
454                     ?>
455                 </div>
456                 <div id="edd_show_terms">
457                     <a href="#" class="edd_terms_links"><?php _e( 'Show Terms', 'edd' ); ?></a>
458                     <a href="#" class="edd_terms_links" style="display:none;"><?php _e( 'Hide Terms', 'edd' ); ?></a>
459                 </div>
460                 <label for="edd_agree_to_terms"><?php echo isset( $edd_options['agree_label'] ) ? $edd_options['agree_label'] : __( 'Agree to Terms?', 'edd' ); ?></label>
461                 <input name="edd_agree_to_terms" class="required" type="checkbox" id="edd_agree_to_terms" value="1"/>
462             </p>
463         </fieldset>
464 <?php
465     }
466 }
467 add_action( 'edd_purchase_form_after_cc_form', 'edd_terms_agreement' );
468 
469 /**
470  * Shows the tax opt-in checkbox
471  *
472  * @since 1.3.3
473  * @global $edd_options Array of all the EDD Options
474  * @return void
475  */
476 function edd_show_local_tax_opt_in() {
477     global $edd_options;
478     if ( edd_use_taxes() && isset( $edd_options['tax_condition'] ) && $edd_options['tax_condition'] == 'local' ) {
479 ?>
480         <fieldset id="edd_tax_opt_in_fields">
481             <p id="edd-tax-opt-in-wrap">
482                 <label for="edd_tax_opt_in"><?php echo isset( $edd_options['tax_location'] ) ? $edd_options['tax_location'] : __( 'Opt Into Taxes?', 'edd' ); ?></label>
483                 <input name="edd_tax_opt_in" type="checkbox" id="edd_tax_opt_in" value="1"<?php checked( true, edd_local_tax_opted_in() ); ?>/>
484             </p>
485         </fieldset>
486 <?php
487     }
488 }
489 add_action( 'edd_purchase_form_before_submit', 'edd_show_local_tax_opt_in' );
490 
491 /**
492  * Shows the final purchase total at the bottom of the checkout page
493  *
494  * @since 1.5
495  * @return void
496  */
497 function edd_checkout_final_total() {
498 ?>
499     <fieldset id="edd_purchase_final_total">
500         <p id="edd_final_total_wrap">
501             <strong><?php _e( 'Purchase Total:', 'edd' ); ?></strong>
502             <span class="edd_cart_amount" data-subtotal="<?php echo edd_get_cart_amount( false ); ?>" data-total="<?php echo edd_get_cart_amount( true, true ); ?>"><?php edd_cart_total(); ?></span>
503         </p>
504     </fieldset>
505 <?php
506 }
507 add_action( 'edd_purchase_form_before_submit', 'edd_checkout_final_total', 999 );
508 
509 
510 /**
511  * Renders the Checkout Submit section
512  *
513  * @since 1.3.3
514  * @return void
515  */
516 function edd_checkout_submit() {
517 ?>
518     <fieldset id="edd_purchase_submit">
519         <?php do_action( 'edd_purchase_form_before_submit' ); ?>
520 
521         <?php edd_checkout_hidden_fields(); ?>
522 
523         <?php echo edd_checkout_button_purchase(); ?>
524 
525         <?php do_action( 'edd_purchase_form_after_submit' ); ?>
526 
527         <?php if ( ! edd_is_ajax_enabled() ) { ?>
528             <p class="edd-cancel"><a href="javascript:history.go(-1)"><?php _e( 'Go back', 'edd' ); ?></a></p>
529         <?php } ?>
530     </fieldset>
531 <?php
532 }
533 add_action( 'edd_purchase_form_after_cc_form', 'edd_checkout_submit', 9999 );
534 
535 /**
536  * Renders the Next button on the Checkout
537  *
538  * @since 1.2
539  * @global $edd_options Array of all the EDD Options
540  * @return string
541  */
542 function edd_checkout_button_next() {
543     global $edd_options;
544 
545     $color = isset( $edd_options[ 'checkout_color' ] ) ? $edd_options[ 'checkout_color' ] : 'gray';
546     $style = isset( $edd_options[ 'button_style' ] ) ? $edd_options[ 'button_style' ] : 'button';
547 
548     ob_start();
549 ?>
550     <input type="submit" id="edd_next_button" class="edd-submit <?php echo $color; ?> <?php echo $style; ?>" value="<?php _e( 'Next', 'edd' ); ?>"/>
551 <?php
552     return apply_filters( 'edd_checkout_button_next', ob_get_clean() );
553 }
554 
555 /**
556  * Renders the Purchase button on the Checkout
557  *
558  * @since 1.2
559  * @global $edd_options Array of all the EDD Options
560  * @return string
561  */
562 function edd_checkout_button_purchase() {
563     global $edd_options;
564 
565     $color = isset( $edd_options[ 'checkout_color' ] ) ? $edd_options[ 'checkout_color' ] : 'gray';
566     $style = isset( $edd_options[ 'button_style' ] ) ? $edd_options[ 'button_style' ] : 'button';
567 
568     $complete_purchase = isset( $edd_options['checkout_label'] ) && strlen( trim( $edd_options['checkout_label'] ) ) > 0 ? $edd_options['checkout_label'] : __( 'Purchase', 'edd' );
569     ob_start();
570 ?>
571     <input type="submit" class="edd-submit <?php echo $color; ?> <?php echo $style; ?>" id="edd-purchase-button" name="edd-purchase" value="<?php echo $complete_purchase; ?>"/>
572 <?php
573     return apply_filters( 'edd_checkout_button_purchase', ob_get_clean() );
574 }
575 
576 /**
577  * Show Payment Icons by getting all the accepted icons from the EDD Settings
578  * then ouputting the icons.
579  *
580  * @since 1.0
581  * @global $edd_options Array of all the EDD Options
582  * @return void
583 */
584 function edd_show_payment_icons() {
585     global $edd_options;
586 
587     if ( isset( $edd_options['accepted_cards'] ) ) {
588         echo '<div class="edd-payment-icons">';
589         foreach( $edd_options['accepted_cards'] as $key => $card ) {
590             if( edd_string_is_image_url( $key ) ) {
591                 echo '<img class="payment-icon" src="' . $key . '"/>';
592             } else {
593                 echo '<img class="payment-icon" src="' . EDD_PLUGIN_URL . 'assets/images/icons/' . strtolower( str_replace( ' ', '', $card ) ) . '.png"/>';
594             }
595         }
596         echo '</div>';
597     }
598 }
599 add_action( 'edd_checkout_form_top', 'edd_show_payment_icons' );
600 
601 /**
602  * Outputs the JavaScript code for the Agree to Terms section to toggle
603  * the T&Cs text
604  *
605  * @since 1.0
606  * @global $edd_options Array of all the EDD Options
607  * @return void
608  */
609 function edd_agree_to_terms_js() {
610     global $edd_options;
611 
612     if ( isset( $edd_options['show_agree_to_terms'] ) ) {
613 ?>
614     <script type="text/javascript">
615         jQuery(document).ready(function($){
616             $('body').on('click', '.edd_terms_links', function(e) {
617                 //e.preventDefault();
618                 $('#edd_terms').slideToggle();
619                 $('.edd_terms_links').toggle();
620                 return false;
621             });
622         });
623     </script>
624 <?php
625     }
626 }
627 add_action( 'edd_checkout_form_top', 'edd_agree_to_terms_js' );
628 
629 /**
630  * Renders the hidden Checkout fields
631  *
632  * @since 1.3.2
633  * @return void
634  */
635 function edd_checkout_hidden_fields() {
636 ?>
637     <?php if ( is_user_logged_in() ) { ?>
638     <input type="hidden" name="edd-user-id" value="<?php echo get_current_user_id(); ?>"/>
639     <?php } ?>
640     <input type="hidden" name="edd_action" value="purchase"/>
641     <input type="hidden" name="edd-gateway" value="<?php echo edd_get_chosen_gateway(); ?>" />
642 <?php
643 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0