edd_apply_preset_discount

Applies the preset discount, if any.

Description

edd_apply_preset_discount(); 

This is separated from edd_listen_for_cart_discount() in order to allow items to be added to the cart and for it to persist across page loads if necessary


Usage

  1. if ( !function_exists( 'edd_apply_preset_discount' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-digital-downloads/includes/discount-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = edd_apply_preset_discount(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/discount-functions.php  
  1. function edd_apply_preset_discount() { 
  2.  
  3. $code = sanitize_text_field( EDD()->session->get( 'preset_discount' ) ); 
  4.  
  5. if ( ! $code ) { 
  6. return; 
  7.  
  8. if ( ! edd_is_discount_valid( $code, '', false ) ) { 
  9. return; 
  10.  
  11. $code = apply_filters( 'edd_apply_preset_discount', $code ); 
  12.  
  13.  
  14. EDD()->session->set( 'preset_discount', null );