Last active
July 29, 2021 12:17
-
-
Save coffee-mug/5ed3879674f6bc23fa90d1b4d34fb731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HOW TO: | |
// 1/ Update the STEPS_TO_CREATE array in the main function with the checkout steps names you want to create. Please list them in order. | |
// 2/ paste the script in the console from the ecommerce settings page. | |
main() | |
function main() { | |
// Indicate desired steps names, in order, that need to be created | |
var STEPS_TO_CREATE = ['shipping', 'payment']; | |
// clear out existing steps | |
reset(); | |
// Perform steps creation | |
createSteps(STEPS_TO_CREATE); | |
// Save changes | |
save(); | |
} | |
function save() { | |
document.querySelector('ga-submit-buttons button').click() | |
} | |
function updateFirstStep(label) { | |
var firstStep = document.querySelector('.ga-draggable-list-edit-content > input'); | |
if (firstStep) { | |
// Toggle edit mode for the step | |
document.querySelector('.ga-draggable-list-pencil').click() | |
// perform the update | |
newStepLabel.value = label; | |
// Necessary for input to take value change into account. | |
var eventChange = document.createEvent("HTMLEvents"); | |
eventChange.initEvent("change", false, true); // adding this created a magic and passes it as if keypressed | |
newStepLabel.dispatchEvent(eventChange); | |
return true; | |
} | |
return false; | |
} | |
function createSteps(stepsLabels) { | |
var updatedFirstStep = updateFirstStep(stepsLabels[0]); | |
if (updatedFirstStep) { | |
stepsLabels.slice(1).forEach(function(step){ | |
createStep(step); | |
}) | |
} else { | |
stepsLabels.forEach(function(step){ | |
createStep(step); | |
}) | |
} | |
} | |
function createStep(label) { | |
var addStep = document.querySelector('.ga-draggable-list-add > button'); | |
addStep.click() | |
// Pick the last step created for update | |
var newStepLabel = Array.from(document.querySelectorAll('.ga-draggable-list-edit-content > input')).slice(-1)[0] | |
newStepLabel.value = label; | |
// Necessary for input to take value change into account. | |
var eventChange = document.createEvent("HTMLEvents"); | |
eventChange.initEvent("change", false, true); // adding this created a magic and passes it as if keypressed | |
newStepLabel.dispatchEvent(eventChange); | |
} | |
function reset() { | |
// Loop that clicks on each remove cross button | |
document.querySelectorAll('.ga-draggable-list-remove').forEach(function(button) { button.click() }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment