Advertisement
ikai2

Recharge on non-product pages

Jun 14th, 2022 (edited)
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 1- Add Block element in each Product Detail and gave it this ID: custom-container
  2.  
  3. // 2- add this class to the block: custom-widget-1
  4.  
  5. // 3- if you want to display recharge for more than one product add the same ID and, Remember that class of Block has to // have a count number such as: custom-widget-1, custom-widget-2, ...)
  6.  
  7. // here's a quick demo: https://www.loom.com/share/98f305e843d2470f8159d5d965739b5f
  8.  
  9.  
  10. // 4- Add this custom javascript into Custom Javascript Modal:
  11.  
  12. window.addEventListener('load', function (){
  13.   const configs = []
  14.   document.querySelectorAll('#custom-container').forEach((container, index) => {
  15.   const productId = container.closest('[data-pf-type=ProductBox]').getAttribute('data-product-id')
  16.   const config = {
  17.     productId: parseInt(productId),
  18.   injectionParent: `.custom-widget-${index + 1}`, // The node that will have the widget injected in
  19.   injectionMethod: 'append', // How will the widget be injected
  20.   injectFn: (node, target) => {}, // Runs a custom injection function
  21.   selectors: {
  22.     price: ['.my-price-selector'], // the selectors that will be updated based on subscription
  23.     variant: ['.variant-selector'] // The variants to watch for to update the subscription prices
  24.   }
  25.   }
  26.   configs.push(config)
  27. })
  28.   setTimeout(() => {
  29.   ReChargeWidget.createWidgets(configs)
  30.   }, 2000)
  31. })
  32.  
  33.  
  34.  
  35. // for product list:
  36.  
  37.  
  38. window.addEventListener('load', function (){
  39. const classes = document.querySelectorAll('.custom-container')
  40. classes.forEach((c, i) => {
  41. c.classList.add(`custom-widget-${i + 1}`)
  42. })
  43.   const configs = []
  44.   document.querySelectorAll('.custom-container').forEach((container, index) => {
  45.   const productId = container.closest('[data-pf-type=ProductBox]').getAttribute('data-product-id')
  46.   const config = {
  47.     productId: parseInt(productId),
  48.   injectionParent: `.custom-widget-${index + 1}`, // The node that will have the widget injected in
  49.   injectionMethod: 'append', // How will the widget be injected
  50.   injectFn: (node, target) => {}, // Runs a custom injection function
  51.   selectors: {
  52.     price: ['.my-price-selector'], // the selectors that will be updated based on subscription
  53.     variant: ['.variant-selector'] // The variants to watch for to update the subscription prices
  54.   }
  55.   }
  56.   configs.push(config)
  57. })
  58.   setTimeout(() => {
  59.   ReChargeWidget.createWidgets(configs)
  60.   }, 2000)
  61. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement