1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20 21 22
23 function edd_add_rewrite_endpoints( $rewrite_rules ) {
24 add_rewrite_endpoint( 'edd-add', EP_ALL );
25 add_rewrite_endpoint( 'edd-remove', EP_ALL );
26 }
27 add_action( 'init', 'edd_add_rewrite_endpoints' );
28
29 30 31 32 33 34 35 36 37
38 function edd_process_cart_endpoints() {
39 global $wp_query;
40
41
42 if ( isset( $wp_query->query_vars['edd-add'] ) ) {
43 $download_id = absint( $wp_query->query_vars['edd-add'] );
44 $cart = edd_add_to_cart( $download_id, array() );
45
46 wp_redirect( edd_get_checkout_uri() ); exit;
47 }
48
49
50 if ( isset( $wp_query->query_vars['edd-remove'] ) ) {
51 $cart_key = absint( $wp_query->query_vars['edd-remove'] );
52 $cart = edd_remove_from_cart( $cart_key );
53
54 wp_redirect( edd_get_checkout_uri() ); exit;
55 }
56 }
57 add_action( 'template_redirect', 'edd_process_cart_endpoints', 100 );
58
59 60 61 62 63 64
65 function edd_process_add_to_cart( $data ) {
66 $download_id = $data['download_id'];
67 $options = isset( $data['edd_options'] ) ? $data['edd_options'] : array();
68 $cart = edd_add_to_cart( $download_id, $options );
69
70 if ( edd_straight_to_checkout() && ! edd_is_checkout() ) {
71 wp_redirect( edd_get_checkout_uri(), 303 );
72 exit;
73 }
74 }
75 add_action( 'edd_add_to_cart', 'edd_process_add_to_cart' );
76
77 78 79 80 81 82
83 function edd_process_remove_from_cart( $data ) {
84 $cart_key = $_GET['cart_item'];
85 $cart = edd_remove_from_cart( $cart_key );
86 }
87 add_action( 'edd_remove', 'edd_process_remove_from_cart' );
88
89 90 91 92 93 94
95 function edd_process_collection_purchase( $data ) {
96 $taxonomy = urldecode( $data['taxonomy'] );
97 $terms = urldecode( $data['terms'] );
98 $cart_items = edd_add_collection_to_cart( $taxonomy, $terms );
99 wp_redirect( add_query_arg( 'added', '1', remove_query_arg( array( 'edd_action', 'taxonomy', 'terms' ) ) ) );
100 exit;
101 }
102 add_action( 'edd_purchase_collection', 'edd_process_collection_purchase' );