function reset_cart() { if (isset($_GET['reset'])) { woocommerce_empty_cart(); wp_redirect(home_url()); exit; } }
function br_submit_registration() { //woocommerce_empty_cart(); global $registration_errors; global $woocommerce; $lower_fee = 4262; $upper_fee = 4254; $prep_fee = 5551; if (isset($_POST['br_register']) && 'br_registration' == $_POST['br_register']) { if (!isset($_POST['registration_n']) || !wp_verify_nonce($_POST['registration_n'], 'registration_action_nonce')) { print 'Sorry, there was a problem processing your request.'; exit; } woocommerce_empty_cart(); $woocommerce->session->player_info = $_POST['camper']; $woocommerce->session->medical_consent = $_POST['medical_consent']; if (is_registration_error()) { return; } foreach ($_POST['camper'] as $player) { $isPrep = strpos($player['grade'], 'prep'); if ($isPrep !== false) { foreach ($player['camp'] as $camp) { if (strpos($camp, 'prep') !== false) { $woocommerce->cart->add_to_cart($prep_fee); } else { $woocommerce->cart->add_to_cart($upper_fee); } } } else { if ($player['grade'] >= 4) { foreach ($player['camp'] as $camp) { $woocommerce->cart->add_to_cart($upper_fee); } } else { foreach ($player['camp'] as $camp) { $woocommerce->cart->add_to_cart($lower_fee); } } } } wp_redirect(home_url('/review-pay')); exit; } }
/** * Checks if the current request is by a user to renew their subscription, and if it is * set up a subscription renewal via the cart for the product/variation that is being renewed. * * @since 1.2 */ public static function maybe_create_renewal_order_for_user() { global $woocommerce; if (isset($_GET['renew_subscription']) && isset($_GET['_wpnonce'])) { $user_id = get_current_user_id(); $subscription = WC_Subscriptions_Manager::get_subscription($_GET['renew_subscription']); if (isset($_GET['role'])) { $role = woocommerce_clean($_GET['role']); } else { $role = 'parent'; } $redirect_to = get_permalink(woocommerce_get_page_id('myaccount')); if (wp_verify_nonce($_GET['_wpnonce'], __FILE__) === false) { $woocommerce->add_error(__('There was an error with the renewal request. Please try again.', WC_Subscriptions::$text_domain)); } elseif (empty($subscription)) { $woocommerce->add_error(__('That doesn\'t appear to be one of your subscriptions.', WC_Subscriptions::$text_domain)); } elseif (!self::can_subscription_be_renewed($_GET['renew_subscription'], $user_id)) { $woocommerce->add_error(__('That subscription can not be renewed. Please contact us if you need assistance.', WC_Subscriptions::$text_domain)); } else { $original_order = new WC_Order($subscription['order_id']); $product_id = $subscription['product_id']; $product = get_product($product_id); // Make sure we don't actually need the variation ID if ($product->is_type(array('variable-subscription'))) { $item = WC_Subscriptions_Order::get_item_by_product_id($original_order, $product_id); $variation_id = $item['variation_id']; $variation = get_product($variation_id); $variation_data = $variation->get_variation_attributes(); } elseif ($product->is_type(array('subscription_variation'))) { // Handle existing renewal orders incorrectly using variation_id as the product_id $product_id = $product->id; $variation_id = $product->get_variation_id(); $variation_data = $product->get_variation_attributes(); } else { $variation_id = ''; $variation_data = array(); } woocommerce_empty_cart(); $woocommerce->cart->add_to_cart($product_id, 1, $variation_id, $variation_data, array('subscription_renewal' => array('original_order' => $original_order->id, 'failed_order' => null, 'role' => $role))); $woocommerce->add_message(__('Renew your subscription.', WC_Subscriptions::$text_domain)); $redirect_to = $woocommerce->cart->get_checkout_url(); } wp_safe_redirect($redirect_to); exit; } }
/** * Renew a membership * * @since 1.0.0 */ public function renew_membership() { if (!isset($_GET['renew_membership']) || !isset($_GET['user_membership_id'])) { return; } $user_membership_id = absint($_GET['user_membership_id']); $user_membership = wc_memberships_get_user_membership($user_membership_id); $membership_plan = $user_membership->get_plan(); $user_can_renew = current_user_can('wc_memberships_renew_membership', $user_membership_id); if (!$user_membership) { wc_add_notice(__('Invalid membership.', WC_Memberships::TEXT_DOMAIN), 'error'); } else { /** * Filter the valid statuses for renewing a user membership on frontend * * @since 1.0.0 * @param array $statuses Array of statuses valid for renewal */ $user_membership_can_renew = in_array($user_membership->get_status(), apply_filters('wc_memberships_valid_membership_statuses_for_renewal', array('expired', 'cancelled'))); // Try to purchase the same product as before $original_product = $user_membership->get_product(); if ($original_product && $original_product->is_purchasable()) { $product = $original_product; } else { foreach ($membership_plan->get_product_ids() as $product_id) { $another_product = wc_get_product($product_id); // We've found a product that can be purchased to renew access! if ($another_product && $another_product->is_purchasable()) { $product = $another_product; break; } } } // We can renew! Let's do it! if ($product && $user_can_renew && $user_membership_can_renew && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'wc_memberships-renew_membership')) { woocommerce_empty_cart(); WC()->cart->add_to_cart($product->id, 1); wc_add_notice(sprintf(__('Renew your membership by purchasing %s.', WC_Memberships::TEXT_DOMAIN), $product->get_title()), 'success'); wp_safe_redirect(WC()->cart->get_checkout_url()); exit; } } wc_add_notice(__('Cannot renew this membership. Please contact us if you need assistance.', WC_Memberships::TEXT_DOMAIN), 'error'); wp_safe_redirect(SV_WC_Plugin_Compatibility::wc_get_page_permalink('myaccount')); exit; }
function populate_cart_if_empty($p_id) { global $woocommerce, $wp_query, $product; $woocommerce->cart->remove_coupons(1); if (!session_id()) { session_start(); } if (isset($_SESSION['flagCheck'])) { unset($_SESSION['flagCheck']); } woocommerce_empty_cart(); return $p_id; }
/** * Checks if the current request is by a user to renew their subscription, and if it is * set up a subscription renewal via the cart for the product/variation that is being renewed. * * @since 1.2 */ public static function maybe_create_renewal_order_for_user() { global $woocommerce; if (isset($_GET['renew_subscription']) && isset($_GET['_wpnonce'])) { $user_id = get_current_user_id(); $subscription = WC_Subscriptions_Manager::get_subscription($_GET['renew_subscription']); if (isset($_GET['role'])) { $role = woocommerce_clean($_GET['role']); } else { $role = 'parent'; } $redirect_to = get_permalink(woocommerce_get_page_id('myaccount')); if (wp_verify_nonce($_GET['_wpnonce'], __FILE__) === false) { WC_Subscriptions::add_notice(__('There was an error with the renewal request. Please try again.', 'woocommerce-subscriptions'), 'error'); } elseif (empty($subscription)) { WC_Subscriptions::add_notice(__('That doesn\'t appear to be one of your subscriptions.', 'woocommerce-subscriptions'), 'error'); } elseif (!self::can_subscription_be_renewed($_GET['renew_subscription'], $user_id)) { WC_Subscriptions::add_notice(__('That subscription can not be renewed. Please contact us if you need assistance.', 'woocommerce-subscriptions'), 'error'); } else { $original_order = new WC_Order($subscription['order_id']); $product_id = $subscription['product_id']; $product = get_product($product_id); $item = WC_Subscriptions_Order::get_item_by_product_id($original_order, $product_id); $variation_id = ''; $variation_data = array(); // Display error message for deleted products if (false === $product) { WC_Subscriptions::add_notice(self::$product_deleted_error_message, 'error'); // Make sure we don't actually need the variation ID (if the product was a variation, it will have a variation ID; however, if the product has changed from a simple subscription to a variable subscription, there will be no variation_id) } elseif ($product->is_type(array('variable-subscription')) && !empty($item['variation_id'])) { $variation_id = $item['variation_id']; $variation = get_product($variation_id); if (false === $variation) { WC_Subscriptions::add_notice(self::$product_deleted_error_message, 'error'); $variation_data = array(); } else { $variation_data = $variation->get_variation_attributes(); } } elseif ($product->is_type(array('subscription_variation'))) { // Handle existing renewal orders incorrectly using variation_id as the product_id $product_id = $product->id; $variation_id = $product->get_variation_id(); $variation_data = $product->get_variation_attributes(); } // Make sure a value is set for each attribute - handles the "catch all" variations which do not have a value set for an attribute, but which will have been set on the cart item when the customer added the item if (!empty($variation_data)) { foreach ($variation_data as $attribute_name => $attribute_value) { if (empty($attribute_value) && !empty($item[str_replace('attribute_', '', $attribute_name)])) { $variation_data[$attribute_name] = $item[str_replace('attribute_', '', $attribute_name)]; } } } $cart_item_data = array('subscription_renewal' => array('original_order' => $original_order->id, 'failed_order' => null, 'role' => $role)); $cart_item_data = apply_filters('woocommerce_order_again_cart_item_data', $cart_item_data, $item, $original_order); woocommerce_empty_cart(); $woocommerce->cart->add_to_cart($product_id, 1, $variation_id, $variation_data, $cart_item_data); WC_Subscriptions::add_notice(__('Renew your subscription.', 'woocommerce-subscriptions'), 'success'); $redirect_to = $woocommerce->cart->get_checkout_url(); } wp_safe_redirect($redirect_to); exit; } }