<?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>WooCommerce | Digital Nomad Blog</title>
	<atom:link href="https://online-dentist.hu/en/tag/woocommerce/feed/" rel="self" type="application/rss+xml" />
	<link>https://online-dentist.hu</link>
	<description></description>
	<lastBuildDate>Sat, 17 Jan 2026 10:40:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://online-dentist.hu/wp-content/uploads/2025/11/cropped-logo_circle_transparent-32x32.png</url>
	<title>WooCommerce | Digital Nomad Blog</title>
	<link>https://online-dentist.hu</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[6] Taking WooCommerce Further: When a Popup Window Sends Data Back to the System</title>
		<link>https://online-dentist.hu/en/taking-woocommerce-further-when-a-popup-window-sends-data-back-to-the-system/</link>
					<comments>https://online-dentist.hu/en/taking-woocommerce-further-when-a-popup-window-sends-data-back-to-the-system/#respond</comments>
		
		<dc:creator><![CDATA[Steve – Digital Nomad]]></dc:creator>
		<pubDate>Thu, 30 Oct 2025 15:42:58 +0000</pubDate>
				<category><![CDATA[How I Built IT]]></category>
		<category><![CDATA[WooCommerce]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://online-dentist.hu/?p=4061</guid>

					<description><![CDATA[<p>A custom WooCommerce feature where a popup window not only displays data but sends it back to the system — redefining how dynamic orders work.</p>
<p>The post <a href="https://online-dentist.hu/en/taking-woocommerce-further-when-a-popup-window-sends-data-back-to-the-system/">[6] Taking WooCommerce Further: When a Popup Window Sends Data Back to the System</a> first appeared on <a href="https://online-dentist.hu">Digital Nomad Blog</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>WooCommerce is a robust, flexible e-commerce engine &#8211; but the real magic happens when we start extending it beyond its standard capabilities.</p>
<p>One of my latest projects did exactly that: I built a dynamic popup window that doesn’t just display information but also communicates directly with WooCommerce, sending data back to the system in real time and influencing the order process itself.</p>
<h3>The Goal</h3>
<p>The goal was to replace a static “extra options” form (for example: cake box, candles, adult extras, etc.) with an interactive popup interface where users could make selections and instantly see updated prices and combinations.</p>
<p>Behind the scenes, JavaScript listens to user interactions and sends updates to the WooCommerce backend via AJAX.</p>
<h2>How It Works</h2>
<p>On the frontend, jQuery monitors each user selection.</p>
<p>When someone chooses a specific cake add-on (like a candle type, color, or decoration), the script:</p>
<ul>
<li>Collects the relevant data- attributes (such as data-price or data-type),</li>
<li>Builds a JSON object from the selection,</li>
<li>Sends it back to the WooCommerce backend via AJAX,</li>
<li>Where a PHP function saves it as custom order meta data.</li>
</ul>
<p>In other words, the popup isn’t just a visual element &#8211; it’s an active UI layer that communicates directly with WooCommerce.</p>
<h3>Key Technologies</h3>
<ul>
<li>JavaScript / jQuery – to manage dynamic elements, events, and value changes.</li>
<li>AJAX <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2194.png" alt="↔" class="wp-smiley" style="height: 1em; max-height: 1em;" /> PHP bridge – to send and receive data between frontend and backend.</li>
<li>WooCommerce hooks (do_action, add_action) – to integrate data into the checkout and order flow.</li>
<li>Custom order meta fields – to store all additional product information (flavor, size, box type, color, etc.).</li>
</ul>
<h3>The Result</h3>
<p>The final product delivers a truly interactive ordering experience:</p>
<ul>
<li>The customer instantly sees updated prices and options.</li>
<li>Once the popup is confirmed, all selected data is automatically transferred to the cart.</li>
<li>The same data appears in the order confirmation emails and in the WooCommerce admin panel.</li>
</ul>
<p>All of this works fully within WooCommerce’s architecture &#8211; no third-party plugins or core file modifications required.</p>
<h3>Summary</h3>
<p>This project demonstrates that WooCommerce is not just an e-commerce engine &#8211; it’s a powerful development framework.</p>
<p>By leveraging WordPress hooks, WooCommerce actions, JavaScript, and AJAX, we can build experiences that feel seamless, dynamic, and deeply integrated.</p>
<p>Here, the popup isn’t just decoration &#8211; it became a vital part of the data flow itself.</p>
<h2>Code Examples</h2>
<h3>1) Minimal popup UI (HTML)</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;!-- Popup modal (example) --&gt;
&lt;div id="cake-extras-popup" class="popup" hidden&gt;
  &lt;h3&gt;Choose extras&lt;/h3&gt;

  &lt;label&gt;Symbol&lt;/label&gt;
  &lt;select id="jel_gyertya"&gt;
    &lt;option value="sziv"&gt;<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2764.png" alt="❤" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Heart&lt;/option&gt;
    &lt;option value="X"&gt;<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2716.png" alt="✖" class="wp-smiley" style="height: 1em; max-height: 1em;" /> X&lt;/option&gt;
    &lt;option value="?"&gt;<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2753.png" alt="❓" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Question&lt;/option&gt;
  &lt;/select&gt;

  &lt;label&gt;Color&lt;/label&gt;
  &lt;select id="jel_gyertya_szin"&gt;
    &lt;option value="csillámos pink"&gt;Glitter Pink&lt;/option&gt;
    &lt;option value="csillámos arany"&gt;Glitter Gold&lt;/option&gt;
    &lt;option value="csillámos ezüst"&gt;Glitter Silver&lt;/option&gt;
  &lt;/select&gt;

  &lt;label&gt;Box&lt;/label&gt;
  &lt;select id="tortadoboz" class="box-selector"&gt;
    &lt;option value="0" data-price="0"&gt;No box&lt;/option&gt;
    &lt;option value="1" data-price="500"&gt;5-slice box (500 Ft)&lt;/option&gt;
    &lt;option value="2" data-price="1000"&gt;10-slice box (1000 Ft)&lt;/option&gt;
  &lt;/select&gt;

  &lt;button id="cake-extras-confirm"&gt;Add to order&lt;/button&gt;
&lt;/div&gt;</pre>
<p>Your real popup can be any UI; what matters is we can read the selections when “Confirm” is clicked.</p>
<h3>2) Enqueue JS and pass AJAX settings (functions.php)</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="php">add_action('wp_enqueue_scripts', function () {
    wp_enqueue_script(
        'cake-extras',
        get_stylesheet_directory_uri() . '/js/cake-extras.js',
        ['jquery'],
        '1.0',
        true
    );

    wp_localize_script('cake-extras', 'CakeAjax', [
        'url'   =&gt; admin_url('admin-ajax.php'),
        'nonce' =&gt; wp_create_nonce('cake_extras_nonce'),
    ]);
});</pre>
<p>&nbsp;</p>
<h3>3) Frontend JS: collect → send via AJAX → store in session</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js">jQuery(function ($) {
  // Example: read price of the selected box
  function getSelectedBoxPrice() {
    const price = $('#tortadoboz option:selected').data('price') || 0;
    return Number(price);
  }

  $('#cake-extras-confirm').on('click', function () {
    const payload = {
      symbol: $('#jel_gyertya').val(),                 // sziv | X | ?
      color:  $('#jel_gyertya_szin').val(),            // e.g. "csillámos arany"
      box:    $('#tortadoboz').val(),                  // 0/1/2...
      box_price: getSelectedBoxPrice(),                // 0 / 500 / 1000
    };

    $.post(CakeAjax.url, {
      action: 'save_cake_extras',
      _ajax_nonce: CakeAjax.nonce,
      data: payload
    }).done(function (res) {
      if (res &amp;&amp; res.success) {
        alert('Extras saved for this order. Now add the product to cart!');
        // Close your modal here.
      } else {
        alert('Could not save extras.');
      }
    });
  });
});</pre>
<p>&nbsp;</p>
<h3>4) PHP AJAX handler: save extras to session</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="php">add_action('wp_ajax_save_cake_extras', 'save_cake_extras');
add_action('wp_ajax_nopriv_save_cake_extras', 'save_cake_extras');

function save_cake_extras() {
    check_ajax_referer('cake_extras_nonce');

    if (empty($_POST['data']) || !class_exists('WC_Session')) {
        wp_send_json_error();
    }

    $raw = (array) $_POST['data'];

    // Sanitize
    $extras = [
        'symbol'    =&gt; sanitize_text_field($raw['symbol'] ?? ''),
        'color'     =&gt; sanitize_text_field($raw['color'] ?? ''),
        'box'       =&gt; sanitize_text_field($raw['box'] ?? ''),
        'box_price' =&gt; floatval($raw['box_price'] ?? 0),
    ];

    if (function_exists('WC') &amp;&amp; WC()-&gt;session) {
        WC()-&gt;session-&gt;set('cake_extras', $extras);
        wp_send_json_success();
    }

    wp_send_json_error();
}</pre>
<p>We temporarily keep the popup data in the WooCommerce session until the product is added to the cart.</p>
<h3>5) Inject session data into the cart item (so it travels through checkout)</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="php">// Attach extras when a product is added to the cart
add_filter('woocommerce_add_cart_item_data', function ($cart_item_data, $product_id, $variation_id) {
    if (function_exists('WC') &amp;&amp; WC()-&gt;session) {
        $extras = WC()-&gt;session-&gt;get('cake_extras');
        if (!empty($extras) &amp;&amp; is_array($extras)) {
            $cart_item_data['cake_extras'] = $extras;

            // Optional: add the box price to the line item price
            if (!empty($extras['box_price'])) {
                $cart_item_data['cake_extras']['_adjust_price'] = (float) $extras['box_price'];
            }

            // Clear session so it doesn't leak to another add_to_cart
            WC()-&gt;session-&gt;__unset('cake_extras');
        }
    }
    return $cart_item_data;
}, 10, 3);</pre>
<p>&nbsp;</p>
<h3>6) Adjust the cart line price (optional: if extras add cost)</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="php">add_action('woocommerce_before_calculate_totals', function ($cart) {
    if (is_admin() &amp;&amp; !defined('DOING_AJAX')) return;
    if (empty($cart) || empty($cart-&gt;get_cart())) return;

    foreach ($cart-&gt;get_cart() as $cart_item_key =&gt; $item) {
        if (!empty($item['cake_extras']['_adjust_price'])) {
            $extra = (float) $item['cake_extras']['_adjust_price'];
            $price = (float) $item['data']-&gt;get_price('edit');
            $item['data']-&gt;set_price($price + $extra);
        }
    }
});</pre>
<p>&nbsp;</p>
<h3>7) Show extras under the product name in Cart/Checkout</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="php">add_filter('woocommerce_get_item_data', function ($item_data, $cart_item) {
    if (empty($cart_item['cake_extras'])) return $item_data;

    $x = $cart_item['cake_extras'];
    if (!empty($x['symbol'])) {
        $item_data[] = [
            'name'  =&gt; __('Symbol', 'your-textdomain'),
            'value' =&gt; esc_html($x['symbol']),
        ];
    }
    if (!empty($x['color'])) {
        $item_data[] = [
            'name'  =&gt; __('Color', 'your-textdomain'),
            'value' =&gt; esc_html($x['color']),
        ];
    }
    if (isset($x['box']) &amp;&amp; $x['box'] !== '') {
        $item_data[] = [
            'name'  =&gt; __('Box', 'your-textdomain'),
            'value' =&gt; esc_html($x['box']),
        ];
    }
    if (!empty($x['box_price'])) {
        $item_data[] = [
            'name'  =&gt; __('Box price', 'your-textdomain'),
            'value' =&gt; wc_price((float) $x['box_price']),
        ];
    }
    return $item_data;
}, 10, 2);</pre>
<p>&nbsp;</p>
<h3>8) Persist extras into the Order Items (so they appear in admin &amp; emails)</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="php">add_action('woocommerce_checkout_create_order_line_item', function ($item, $cart_item_key, $values, $order) {
    if (empty($values['cake_extras'])) return;

    $x = $values['cake_extras'];
    if (!empty($x['symbol'])) {
        $item-&gt;add_meta_data(__('Symbol', 'your-textdomain'), $x['symbol']);
    }
    if (!empty($x['color'])) {
        $item-&gt;add_meta_data(__('Color', 'your-textdomain'), $x['color']);
    }
    if (isset($x['box']) &amp;&amp; $x['box'] !== '') {
        $item-&gt;add_meta_data(__('Box', 'your-textdomain'), $x['box']);
    }
    if (!empty($x['box_price'])) {
        $item-&gt;add_meta_data(__('Box price', 'your-textdomain'), wc_price((float) $x['box_price']));
    }
}, 10, 4);</pre>
<p>WooCommerce will render order item meta in the admin order screen and in customer/admin emails automatically. If you need a custom layout, hook into the email templates (e.g., woocommerce_email_order_meta or override an email template).</p>
<h3>9) (Optional) Toggle an “adults only” label based on selected extras</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js">jQuery(function ($) {
  $(document).on('change', '.step[data-step="2"] .addon[data-adult="1"] input[type="checkbox"]', function () {
    let hasAdult = false;
    $('.step[data-step="2"] .addon[data-adult="1"] input[type="checkbox"]').each(function () {
      if ($(this).is(':checked')) hasAdult = true;
    });
    window.CakeOrder = window.CakeOrder || {};
    CakeOrder.hasAdultExtra = hasAdult;
    $('#cake-order label.adult')[hasAdult ? 'show' : 'hide']();
  });
});</pre>
<p>&nbsp;</p>
<h2>Why these examples matter</h2>
<ul>
<li>Popup → AJAX → Session keeps the UI responsive while safely handing off data to WooCommerce.</li>
<li>Cart item data + order item meta ensures data survives the entire checkout and lands in emails/admin.</li>
<li>Price adjustment hook keeps the total correct without hacking product data.</li>
<li>No core edits: everything is done via hooks and a tiny script, which is update-safe.</li>
</ul>
<p>&nbsp;</p>
<p>If you want, I can bundle these into a single paste-ready mini-plugin structure so you can drop it into /wp-content/plugins/ and activate.</p><p>The post <a href="https://online-dentist.hu/en/taking-woocommerce-further-when-a-popup-window-sends-data-back-to-the-system/">[6] Taking WooCommerce Further: When a Popup Window Sends Data Back to the System</a> first appeared on <a href="https://online-dentist.hu">Digital Nomad Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://online-dentist.hu/en/taking-woocommerce-further-when-a-popup-window-sends-data-back-to-the-system/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Object Caching 57/68 objects using Disk
Page Caching using Disk: Enhanced 

Page cache debug info:
Engine:             Disk: Enhanced
Cache key:          online-dentist.hu/en/tag/woocommerce/feed/_index_slash_ssl.xml
Creation Time:      1790708306.000s
Header info:
Last-Modified:      Tue, 29 Sep 2026 18:08:57 GMT
ETag:               "2a80fe289e2fbf277150c08c0a0705c0"
X-Powered-By:       W3 Total Cache
X-Robots-Tag:       noindex, follow
Link:               <https://online-dentist.hu/wp-json/>; rel="https://api.w.org/"
Link:               <https://online-dentist.hu/wp-json/wp/v2/tags/540>; rel="alternate"; title="JSON"; type="application/json"
Content-Type:       application/rss+xml; charset=UTF-8

Database Caching 1/38 queries in 0.025 seconds using Disk (Request-wide modification query)

Served from: online-dentist.hu @ 2026-09-29 18:58:26 by W3 Total Cache
-->