Transfer variant colour & size optionBox selection state to duplicate 'Personalised' product page

matchamandmary
New Member
6 0 0
I have created a simple bit of code inside the main-product.liquid code that adds an additional 'Add Personalisation' button to the product pages - above the Add To Cart button.  When clicked the current product URL gets appended with a '-personalised' on the end which links it to the duplicate personalised product with the exception of allowing personalised text to be added (default_product_name + "-personalised").  The same applies in reverse if the visitor wants to remove the Personalisation they click the button again and it removes the '-personalised' text from the string and takes you back to the standard product.  A simple 'custom_on' or 'custom_off' tag on every product determines if the personalised text is added or removed.
 
                {% for tag in product.tags %}
                {% if tag == 'custom_off' %}
                  {% assign product_paired_url = product.url | append: "-personalised"%}
                      <!--Button to switch OFF - currently {{ tag }}-->
                      <a href={{ product_paired_url }}><button type="button" name="customise" class="product-form__submit button button--full-width button--secondary">
                          Add Personalisation
                            </button></a>
                {% elsif tag == 'custom_on' %}
                {% assign product_paired_url = product.url | remove: "-personalised" %}
                      <!--Button to switch OFF - currently {{ tag }}-->
                      <a href={{ product_paired_url }}><button type="button" name="customise" class="product-form__submit button button--full-width button--secondary">
                          Remove Personalisation
                            </button></a>
                {% else %}
                <!--This product has no custom tags - {{ tag }}-->
                {% endif %}
                {% endfor %}
 
This is very simple and means every time you press the button, the colour & size selections (on variants) are lost and the link goes to the default product.  The bit I am struggling with is the liquid logic for the button url to navigate over to the personalised product and match the current product state of the colour & size to the mirrored/personalised products variant settings which have same variants but different variant id's but- or in reality, query those selected settings, match via the colour & size to the personalised product and re-apply them.
 
If anyone can offer any advice I would really appreciate it.
 
Thanks
Replies 0 (0)