/** * Process the Cart Restoration * * @since 1.8 * @return mixed || false Returns false if cart saving is disabled */ function edd_restore_cart() { if (edd_is_cart_saving_disabled()) { return false; } $user_id = get_current_user_id(); $saved_cart = get_user_meta($user_id, 'edd_saved_cart', true); $token = edd_get_cart_token(); if (is_user_logged_in() && $saved_cart) { $messages = EDD()->session->get('edd_cart_messages'); if (!$messages) { $messages = array(); } if (isset($_GET['edd_cart_token']) && $_GET['edd_cart_token'] != $token) { $messages['edd_cart_restoration_failed'] = sprintf('<strong>%1$s</strong>: %2$s', __('Error', 'edd'), __('Cart restoration failed. Invalid token.', 'edd')); EDD()->session->set('edd_cart_messages', $messages); } delete_user_meta($user_id, 'edd_saved_cart'); delete_user_meta($user_id, 'edd_cart_token'); if (isset($_GET['edd_cart_token']) && $_GET['edd_cart_token'] != $token) { return new WP_Error('invalid_cart_token', __('The cart cannot be restored. Invalid token.', 'edd')); } } elseif (!is_user_logged_in() && isset($_COOKIE['edd_saved_cart']) && $token) { $saved_cart = $_COOKIE['edd_saved_cart']; if ($_GET['edd_cart_token'] != $token) { $messages['edd_cart_restoration_failed'] = sprintf('<strong>%1$s</strong>: %2$s', __('Error', 'edd'), __('Cart restoration failed. Invalid token.', 'edd')); EDD()->session->set('edd_cart_messages', $messages); return new WP_Error('invalid_cart_token', __('The cart cannot be restored. Invalid token.', 'edd')); } $saved_cart = maybe_unserialize(stripslashes($saved_cart)); setcookie('edd_saved_cart', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN); setcookie('edd_cart_token', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN); } $messages['edd_cart_restoration_successful'] = sprintf('<strong>%1$s</strong>: %2$s', __('Success', 'edd'), __('Cart restored successfully.', 'edd')); EDD()->session->set('edd_cart', $saved_cart); EDD()->session->set('edd_cart_messages', $messages); return true; }
<?php endif; ?> </td> <?php do_action( 'edd_cart_fee_rows_after', $fee_id, $fee ); ?> </tr> <?php endforeach; ?> <?php endif; ?> <?php do_action( 'edd_cart_items_after' ); ?> </tbody> <tfoot> <?php if( has_action( 'edd_cart_footer_buttons' ) ) : ?> <tr class="edd_cart_footer_row<?php if ( edd_is_cart_saving_disabled() ) { echo ' edd-no-js'; } ?>"> <th colspan="<?php echo edd_checkout_cart_columns(); ?>"> <?php do_action( 'edd_cart_footer_buttons' ); ?> </th> </tr> <?php endif; ?> <?php if( edd_use_taxes() ) : ?> <tr class="edd_cart_footer_row edd_cart_subtotal_row"<?php if ( ! edd_is_cart_taxed() ) echo ' style="display:none;"'; ?>> <?php do_action( 'edd_checkout_table_subtotal_first' ); ?> <th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_subtotal"> <?php _e( 'Subtotal', 'edd' ); ?>: <span class="edd_cart_subtotal_amount"><?php echo edd_cart_subtotal(); ?></span> </th> <?php do_action( 'edd_checkout_table_subtotal_last' ); ?> </tr> <?php endif; ?>
?> <?php } ?> <?php do_action('edd_cart_items_after'); ?> </tbody> <tfoot> <?php if (has_action('edd_cart_footer_buttons')) { ?> <tr class="edd_cart_footer_row<?php if (edd_is_cart_saving_disabled()) { echo ' edd-no-js'; } ?> "> <th colspan="<?php echo edd_checkout_cart_columns(); ?> "> <?php do_action('edd_cart_footer_buttons'); ?> </th> </tr> <?php }
/** * Displays the restore cart link on the empty cart page, if a cart is saved * * @since 1.8 * @return void */ function edd_empty_cart_restore_cart_link() { if (edd_is_cart_saving_disabled()) { return; } if (edd_is_cart_saved()) { echo ' <a class="edd-cart-saving-link" id="edd-restore-cart-link" href="' . esc_url(add_query_arg(array('edd_action' => 'restore_cart', 'edd_cart_token' => edd_get_cart_token()))) . '">' . __('Restore Previous Cart.', 'easy-digital-downloads') . '</a>'; } }