Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed logic, redirect to cart #14

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion extralsc-woocommerce-share-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@
// Försök att skapa tabeller
try {
if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}extralsc_wsc_carts'") !== $wpdb->prefix . 'extralsc_wsc_carts') {
$wpdb->query($sql_carts);

Check failure on line 94 in extralsc-woocommerce-share-cart.php

View workflow job for this annotation

GitHub Actions / VIPCS

Use placeholders and $wpdb->prepare(); found $sql_carts
}

if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}extralsc_wsc_products'") !== $wpdb->prefix . 'extralsc_wsc_products') {
$wpdb->query($sql_products);

Check failure on line 98 in extralsc-woocommerce-share-cart.php

View workflow job for this annotation

GitHub Actions / VIPCS

Use placeholders and $wpdb->prepare(); found $sql_products
}

if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}extralsc_wsc_cart_items'") !== $wpdb->prefix . 'extralsc_wsc_cart_items') {
$wpdb->query($sql_cart_items);

Check failure on line 102 in extralsc-woocommerce-share-cart.php

View workflow job for this annotation

GitHub Actions / VIPCS

Use placeholders and $wpdb->prepare(); found $sql_cart_items
}

if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}extralsc_wsc_cart_sharing'") !== $wpdb->prefix . 'extralsc_wsc_cart_sharing') {
Expand Down Expand Up @@ -168,7 +168,7 @@
add_action('template_redirect', 'extralsc_wsc_template_redirect');

// Shortcode för att visa kundvagn baserat på cart_id
function extralsc_display_cart_by_id_shortcode()
function extralsc_display_cart_by_id_shortcode_legacy()
{
if (isset($_GET['cart_id'])) {
$cart_id = sanitize_text_field($_GET['cart_id']); // Sanera input
Expand Down Expand Up @@ -214,6 +214,34 @@
return '<p>Ingen kundvagn angiven.</p>';
}
}

function extralsc_display_cart_by_id_shortcode()
{
if (isset($_GET['cart_id'])) {
$cart_id = sanitize_text_field($_GET['cart_id']); // Sanera input

$cart_data = extralsc_get_cart_data($cart_id);

if ($cart_data) {
WC()->cart->empty_cart();

foreach ($cart_data->items as $item) {
$item = (object) $item;
WC()->cart->add_to_cart($item->product_id, $item->quantity);
}

echo __('Loading...', 'extralsc-wsc');
$cart_url = wc_get_cart_url();
wp_safe_redirect($cart_url);

} else {
return '<p>Kundvagnen kunde inte hittas.</p>';
}
} else {
return '<p>Ingen kundvagn angiven.</p>';
}
}

add_shortcode('display_cart', 'extralsc_display_cart_by_id_shortcode');

// Funktion för att hämta kundvagnsdata och produktinformation
Expand Down
Loading