<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Button Archiv - Homepage nach Preis - Webseite erstellen lassen</title>
	<atom:link href="https://homepage-nach-preis.de/wort/button/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>★ Responsive Webdesigner Homepage erstellen lassen, bereits ab 299 Euro professionelle Webseite. ✓ Google-Optimiert ✓ Mobil-Optimiert &#124; Webdesign &#38; Seo</description>
	<lastBuildDate>Mon, 15 Apr 2024 14:31:43 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://homepage-nach-preis.de/wp-content/uploads/2021/02/cropped-icon-150x150.png</url>
	<title>Button Archiv - Homepage nach Preis - Webseite erstellen lassen</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WooCommerce Warenkorb Leeren &#038; Session Button</title>
		<link>https://homepage-nach-preis.de/2024/04/15/woocommerce-warenkorb-leeren-session-button/</link>
					<comments>https://homepage-nach-preis.de/2024/04/15/woocommerce-warenkorb-leeren-session-button/#respond</comments>
		
		<dc:creator><![CDATA[Homepage-nach-Preis]]></dc:creator>
		<pubDate>Mon, 15 Apr 2024 14:27:03 +0000</pubDate>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Onlineshop]]></category>
		<category><![CDATA[Wordpress Code]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[leeren]]></category>
		<category><![CDATA[Warenkorb]]></category>
		<category><![CDATA[Woocommerce]]></category>
		<guid isPermaLink="false">https://homepage-nach-preis.de/?p=8204</guid>

					<description><![CDATA[<p>Das HNP Warenkorb Leeren Button Plugin für WooCommerce und WordPress erzeugt einen Button auf der Warenkorb-Seite, welcher bei Betätigung den kompletten Warenkorb leert und zudem die Session und Cookies resetet. Download: [sdm_download id=&#8221;8202&#8243; fancy=&#8221;0&#8243;] &#x3C;?php /** Plugin Name: HNP Clear WooCommerce Cart &#x26; Session Description: Ein Plugin zum Leeren des WooCommerce Warenkorbs und L&#xF6;schen von Sessions und Cookies. Version: 1.2 Author: HNP C.R. Author URI: https://homepage-nach-preis.de/ License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html */ // Exit, wenn der Direktzugriff verhindert ist if (!defined(&#x27;ABSPATH&#x27;)) { exit; } function hnp_cwc_enqueue_scripts() { if (is_cart() &#x26;&#x26; get_option(&#x27;hnp_cwc_enable&#x27;, &#x27;no&#x27;) == &#x27;yes&#x27; &#x26;&#x26; get_option(&#x27;hnp_cwc_hook_enable&#x27;, &#x27;no&#x27;) == &#x27;yes&#x27;) { $nonce = wp_create_nonce(&#x27;hnp_cwc_nonce&#x27;); $script = &#x22; var ajaxurl = &#x27;&#x22; . admin_url(&#x27;admin-ajax.php&#x27;) . &#x22;&#x27;; var nonce = &#x27;&#x22; . $nonce . &#x22;&#x27;; document.addEventListener(&#x27;DOMContentLoaded&#x27;, function() { var clearCartButton = document.getElementById(&#x27;clear-cart&#x27;); clearCartButton.addEventListener(&#x27;click&#x27;, function() { // Clear cart var xhr = new XMLHttpRequest(); xhr.open(&#x27;POST&#x27;, ajaxurl, true); xhr.setRequestHeader(&#x27;Content-Type&#x27;, &#x27;application/x-www-form-urlencoded&#x27;); xhr.setRequestHeader(&#x27;X-WP-Nonce&#x27;, nonce); xhr.onload = function() { if (this.status &#x3E;= 200 &#x26;&#x26; this.status &#x3C; 400) { console.log(&#x27;Cart Cleared&#x27;, this.responseText); // Clear sessions and cookies var xhr2 = new XMLHttpRequest(); xhr2.open(&#x27;POST&#x27;, ajaxurl, true); xhr2.setRequestHeader(&#x27;Content-Type&#x27;, &#x27;application/x-www-form-urlencoded&#x27;); xhr2.setRequestHeader(&#x27;X-WP-Nonce&#x27;, nonce); xhr2.onload = function() { if (this.status &#x3E;= 200 &#x26;&#x26; this.status &#x3C; 400) { console.log(&#x27;Sessions and Cookies Cleared&#x27;, this.responseText); // Reload....</p>
<p>Der Beitrag <a rel="nofollow" href="https://homepage-nach-preis.de/2024/04/15/woocommerce-warenkorb-leeren-session-button/">WooCommerce Warenkorb Leeren &#038; Session Button</a> erschien zuerst auf <a rel="nofollow" href="https://homepage-nach-preis.de">Homepage nach Preis - Webseite erstellen lassen</a>. Geschrieben von <a rel="nofollow" href="https://homepage-nach-preis.de/author/homepageadmin/">Homepage-nach-Preis</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Das HNP Warenkorb Leeren Button Plugin für WooCommerce und WordPress erzeugt einen Button auf der Warenkorb-Seite, welcher bei Betätigung den kompletten Warenkorb leert und zudem die Session und Cookies resetet.</p>
<p><strong>Download: </strong><br />
[sdm_download id=&#8221;8202&#8243; fancy=&#8221;0&#8243;]</p>
<pre>
&#x3C;?php
/**
Plugin Name: HNP Clear WooCommerce Cart &#x26; Session
Description: Ein Plugin zum Leeren des WooCommerce Warenkorbs und L&#xF6;schen von Sessions und Cookies.
Version: 1.2
Author: HNP C.R.
Author URI: https://homepage-nach-preis.de/
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
 */

// Exit, wenn der Direktzugriff verhindert ist
if (!defined(&#x27;ABSPATH&#x27;)) {
    exit;
}

function hnp_cwc_enqueue_scripts() {
    if (is_cart() &#x26;&#x26; get_option(&#x27;hnp_cwc_enable&#x27;, &#x27;no&#x27;) == &#x27;yes&#x27; &#x26;&#x26; get_option(&#x27;hnp_cwc_hook_enable&#x27;, &#x27;no&#x27;) == &#x27;yes&#x27;) {
        $nonce = wp_create_nonce(&#x27;hnp_cwc_nonce&#x27;);
        
        $script = &#x22;
            var ajaxurl = &#x27;&#x22; . admin_url(&#x27;admin-ajax.php&#x27;) . &#x22;&#x27;;
            var nonce = &#x27;&#x22; . $nonce . &#x22;&#x27;;
            
            document.addEventListener(&#x27;DOMContentLoaded&#x27;, function() {
                var clearCartButton = document.getElementById(&#x27;clear-cart&#x27;);
                
                clearCartButton.addEventListener(&#x27;click&#x27;, function() {
                    // Clear cart
                    var xhr = new XMLHttpRequest();
                    xhr.open(&#x27;POST&#x27;, ajaxurl, true);
                    xhr.setRequestHeader(&#x27;Content-Type&#x27;, &#x27;application/x-www-form-urlencoded&#x27;);
                    xhr.setRequestHeader(&#x27;X-WP-Nonce&#x27;, nonce);
                    xhr.onload = function() {
                        if (this.status &#x3E;= 200 &#x26;&#x26; this.status &#x3C; 400) {
                            console.log(&#x27;Cart Cleared&#x27;, this.responseText);
                            
                            // Clear sessions and cookies
                            var xhr2 = new XMLHttpRequest();
                            xhr2.open(&#x27;POST&#x27;, ajaxurl, true);
                            xhr2.setRequestHeader(&#x27;Content-Type&#x27;, &#x27;application/x-www-form-urlencoded&#x27;);
                            xhr2.setRequestHeader(&#x27;X-WP-Nonce&#x27;, nonce);
                            xhr2.onload = function() {
                                if (this.status &#x3E;= 200 &#x26;&#x26; this.status &#x3C; 400) {
                                    console.log(&#x27;Sessions and Cookies Cleared&#x27;, this.responseText);
                                    
                                    // Reload the page after clearing cart and sessions/cookies
                                    location.reload();
                                } else {
                                    console.error(&#x27;Error clearing sessions and cookies&#x27;, this);
                                }
                            };
                            xhr2.onerror = function() {
                                console.error(&#x27;Error clearing sessions and cookies&#x27;, this);
                            };
                            xhr2.send(&#x27;action=hnp_clear_sessions_cookies&#x26;nonce=&#x27; + nonce);
                            
                        } else {
                            console.error(&#x27;Error clearing cart&#x27;, this);
                        }
                    };
                    xhr.onerror = function() {
                        console.error(&#x27;Error clearing cart&#x27;, this);
                    };
                    xhr.send(&#x27;action=hnp_clear_cart_session&#x26;nonce=&#x27; + nonce);
                });
            });
        &#x22;;
        wp_add_inline_script(&#x27;jquery&#x27;, $script);
    }
}


add_action(&#x27;wp_enqueue_scripts&#x27;, &#x27;hnp_cwc_enqueue_scripts&#x27;);



// Register shortcode
function hnp_cwc_button_shortcode() {
    ob_start(); ?&#x3E;
    &#x3C;button id=&#x22;clear-cart&#x22;&#x3E;Warenkorb leeren&#x3C;/button&#x3E;
    &#x3C;?php
    return ob_get_clean();
}
add_shortcode(&#x27;hnp_cwc_button&#x27;, &#x27;hnp_cwc_button_shortcode&#x27;);

// Hook to display the button on cart page
function hnp_cwc_display_button() {
    if (get_option(&#x27;hnp_cwc_hook_enable&#x27;, &#x27;no&#x27;) == &#x27;yes&#x27;) {
        echo do_shortcode(&#x27;[hnp_cwc_button]&#x27;);
    }
}
add_action(&#x27;woocommerce_cart_actions&#x27;, &#x27;hnp_cwc_display_button&#x27;);

// AJAX handler to clear cart
function hnp_cwc_clear_cart() {
    check_ajax_referer(&#x27;hnp_cwc_nonce&#x27;, &#x27;nonce&#x27;);

    try {
        WC()-&#x3E;cart-&#x3E;empty_cart();
        echo &#x27;Cart Cleared&#x27;;
    } catch (Exception $e) {
        echo &#x27;Error clearing cart: &#x27; . $e-&#x3E;getMessage();
    }
    die();
}

add_action(&#x27;wp_ajax_hnp_clear_cart_session&#x27;, &#x27;hnp_cwc_clear_cart&#x27;);
add_action(&#x27;wp_ajax_nopriv_hnp_clear_cart_session&#x27;, &#x27;hnp_cwc_clear_cart&#x27;);

</pre>
<pre>

// AJAX handler to clear sessions and cookies
function hnp_cwc_clear_sessions_cookies() {
    check_ajax_referer(&#x27;hnp_cwc_nonce&#x27;, &#x27;nonce&#x27;);

    try {
        // Reset WooCommerce session
        WC()-&#x3E;session-&#x3E;set_customer_session_cookie(false);
        WC()-&#x3E;session-&#x3E;set_session_cookie(false);
        WC()-&#x3E;session-&#x3E;reset_session();

        // Unset all cookies
        foreach ($_COOKIE as $cookie_key =&#x3E; $cookie_value) {
            unset($_COOKIE[$cookie_key]);
            setcookie($cookie_key, &#x27;&#x27;, time() - 3600, &#x27;/&#x27;, $_SERVER[&#x27;HTTP_HOST&#x27;]);
            setcookie($cookie_key, &#x27;&#x27;, time() - 3600, &#x27;/&#x27;, &#x27;.&#x27; . $_SERVER[&#x27;HTTP_HOST&#x27;]);
        }

        echo &#x27;Sessions and Cookies Cleared&#x27;;
    } catch (Exception $e) {
        echo &#x27;Error clearing sessions and cookies: &#x27; . $e-&#x3E;getMessage();
    }
    die();
}


add_action(&#x27;wp_ajax_hnp_clear_sessions_cookies&#x27;, &#x27;hnp_cwc_clear_sessions_cookies&#x27;);
add_action(&#x27;wp_ajax_nopriv_hnp_clear_sessions_cookies&#x27;, &#x27;hnp_cwc_clear_sessions_cookies&#x27;);


// Admin settings
function hnp_cwc_admin_menu() {
    add_menu_page(
        &#x27;HNP Clear WooCommerce Cart Settings&#x27;, 
        &#x27;HNP Clear WooCommerce Cart&#x27;,           
        &#x27;manage_options&#x27;,                   
        &#x27;hnp_cwc_settings&#x27;,                 
        &#x27;hnp_cwc_settings_page&#x27;,            
&#x9;&#x9; plugin_dir_url(__FILE__) . &#x27;img/hnp-favi.png&#x27;                               
    );
}
add_action(&#x27;admin_menu&#x27;, &#x27;hnp_cwc_admin_menu&#x27;);

function hnp_cwc_settings_page() {
&#x9;if (!current_user_can(&#x27;manage_options&#x27;)) {
        return;
    }
    if ($_SERVER[&#x27;REQUEST_METHOD&#x27;] === &#x27;POST&#x27; &#x26;&#x26; check_admin_referer(&#x27;hnp_cwc_nonce&#x27;, &#x27;hnp_cwc_nonce_field&#x27;)) {
        if (isset($_POST[&#x27;hnp_cwc_enable&#x27;])) {
            update_option(&#x27;hnp_cwc_enable&#x27;, $_POST[&#x27;hnp_cwc_enable&#x27;]);
        } else {
            update_option(&#x27;hnp_cwc_enable&#x27;, &#x27;no&#x27;);
        }

        if (isset($_POST[&#x27;hnp_cwc_hook_enable&#x27;])) {
            update_option(&#x27;hnp_cwc_hook_enable&#x27;, $_POST[&#x27;hnp_cwc_hook_enable&#x27;]);
        } else {
            update_option(&#x27;hnp_cwc_hook_enable&#x27;, &#x27;no&#x27;);
        }
    }

    $enabled = get_option(&#x27;hnp_cwc_enable&#x27;, &#x27;no&#x27;);
    $hook_enabled = get_option(&#x27;hnp_cwc_hook_enable&#x27;, &#x27;no&#x27;);
    $nonce = wp_create_nonce(&#x27;hnp_cwc_nonce&#x27;);
    ?&#x3E;
    &#x3C;div class=&#x22;wrap&#x22;&#x3E;
        &#x3C;h2&#x3E;HNP Clear WooCommerce Cart Settings&#x3C;/h2&#x3E;
        &#x3C;form method=&#x22;post&#x22; action=&#x22;&#x22;&#x3E;
            &#x3C;?php wp_nonce_field(&#x27;hnp_cwc_nonce&#x27;, &#x27;hnp_cwc_nonce_field&#x27;); ?&#x3E;
            &#x3C;table class=&#x22;form-table&#x22;&#x3E;
                &#x3C;tr&#x3E;
                    &#x3C;th scope=&#x22;row&#x22;&#x3E;Allgemeine Funktion aktivieren&#x3C;/th&#x3E;
                    &#x3C;td&#x3E;
                        &#x3C;input type=&#x22;checkbox&#x22; name=&#x22;hnp_cwc_enable&#x22; value=&#x22;yes&#x22; &#x3C;?php checked(&#x27;yes&#x27;, $enabled); ?&#x3E; /&#x3E;
                    &#x3C;/td&#x3E;
                &#x3C;/tr&#x3E;
                &#x3C;tr&#x3E;
                    &#x3C;th scope=&#x22;row&#x22;&#x3E;Hook f&#xFC;r Warenkorb aktivieren&#x3C;/th&#x3E;
                    &#x3C;td&#x3E;
                        &#x3C;input type=&#x22;checkbox&#x22; name=&#x22;hnp_cwc_hook_enable&#x22; value=&#x22;yes&#x22; &#x3C;?php checked(&#x27;yes&#x27;, $hook_enabled); ?&#x3E; /&#x3E;
                    &#x3C;/td&#x3E;
                &#x3C;/tr&#x3E;
&#x9;&#x9;&#x9;&#x9;&#x3C;tr&#x3E;Shortcode um den Button manuell einzubinden: [hnp_cwc_button]&#x3C;/tr&#x3E;
            &#x3C;/table&#x3E;
            &#x3C;?php submit_button(); ?&#x3E;
        &#x3C;/form&#x3E;
    &#x3C;/div&#x3E;
    &#x3C;?php
}

</pre>
<p>Der Beitrag <a rel="nofollow" href="https://homepage-nach-preis.de/2024/04/15/woocommerce-warenkorb-leeren-session-button/">WooCommerce Warenkorb Leeren &#038; Session Button</a> erschien zuerst auf <a rel="nofollow" href="https://homepage-nach-preis.de">Homepage nach Preis - Webseite erstellen lassen</a>. Geschrieben von <a rel="nofollow" href="https://homepage-nach-preis.de/author/homepageadmin/">Homepage-nach-Preis</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://homepage-nach-preis.de/2024/04/15/woocommerce-warenkorb-leeren-session-button/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
