baldursson
Forum Replies Created
-
Forum: Plugins
In reply to: [All-in-One WP Migration and Backup] WP-CliOk, I finally cracked it myself. I was using
$_SERVER['DOCUMENT_ROOT']inwp-config.phpto set path to wp-content. That apparently doesn’t work so good with wp-cli, so I just replaced it withdirname(__FILE__)Forum: Plugins
In reply to: Woocommerce – Replacing Price Range When Variation SelectedI also needed a solution for this, and came up with what I thought was an innovative piece of code 🙂
You can see if a variation has been selected by looking at the “add to cart” button. When a variation hasn’t been selected yet, it has the class
wc-variation-selection-needed.By using a
MutationObserver(Browser Compatibility), I detected changes to the state of the form by observing attributes of the “add to cart” button. When it has the classwc-variation-selection-needed, I display the price range, otherwise I hide it.The result: When a variation is selected I see the proper price, when it isn’t I see the price range instead. Here is some code you can use:
var cartButton = document.querySelector('.variations_button'); var observer = new MutationObserver( function(mutations) { priceChangeCallback(mutations); } ); var config = { attributes: true }; observer.observe(cartButton, config); function priceChangeCallback(mutations) { if (!!document.querySelector('.wc-variation-selection-needed')) { document.querySelector('.price-range').classList.remove('hidden'); } else { document.querySelector('.price-range').classList.add('hidden'); } }