Update product price when form total changes

Instructions

Code

Filename: gspc-update-wc-price-when-form-total-changes.js

/**
 * Gravity Shop // Product Configurator // Update product price when form total changes
 * https://gravitywiz.com/documentation/gravity-shop-product-configurator/
 *
 * Instructions:
 *  1. Add to form using https://gravitywiz.com/gravity-forms-code-chest/
 */
jQuery('.ginput_total_GFFORMID').on('change', function() {
  var total = jQuery(this).val();
  var formatted = gformFormatMoney(total, true);

  // Find any character outside of 0-9, period, or comma and wrap it with span.woocommerce-Price-currencySymbol
  formatted = formatted.replace(/[^0-9\.,]/g, '<span class="woocommerce-Price-currencySymbol">$&</span>');

  jQuery('p.price .woocommerce-Price-amount bdi').html(formatted);
});

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.