Getting Snipcart custom data attributes into WordPress + Elementor Pricing Table

After shunning pagebuilders in WordPress long enough, I gave Elementor a try for a landing page layout and found it quite useful. I also realized how terribly far behind Gutenberg is!

So, Elementor got me 90% of the way there, as is often the case in WordPress – simple, until it isn’t!

Custom code in the theme’s functions.php got the last piece of the puzzle:

function wp2static_snipcart_callback($buffer) {
   $html_output = $buffer;

   $dom = new DOMDocument();

   $finder = new DomXPath($dom);
   $nodes = $finder->query("//*[contains(@class, '$classname')]");

   $yearly_buy_button = $nodes->item(1);

   $yearly_buy_button->setAttribute('class','elementor-price-table__button elementor-button elementor-size-md snipcart-add-item');                                                                
   $yearly_buy_button->setAttribute('data-item-name','PowerPack, unlimited sites, yearly');

   $unlimited_buy_button = $nodes->item(2);

   $unlimited_buy_button->setAttribute('class','elementor-price-table__button elementor-button elementor-size-md snipcart-add-item');                                                             
   $unlimited_buy_button->setAttribute('data-item-name','PowerPack, unlimited sites, lifetime');

   return $dom->saveHTML();

add_filter( 'the_content', 'wp2static_snipcart_callback' );

// duplicate with wp_styles for loaded CSS in frontend
function insite_inspect_scripts() {
global $wp_scripts; echo PHP_EOL.’’.PHP_EOL;

add_action( ‘wp_print_scripts’, ‘insite_inspect_scripts’ );
Share on twitter
Share on reddit
Share on telegram
Share on email
Share on print

Site made with love of these open source tools

The beautifully-crafted OS that forces you to learn how to do things properly.

For better or worse, WordPress powers 30% of the web. ClassicPress reduces some of the bloat.

Text is my material. Learn one text editor well.

Version controlling all the things.

Retaining workspaces on local and remote servers.

Supporting the OpenBSD community with opinionated VMs. €10/yr donated to the OpenBSD Foundation.

To Roman Zolotarev, for helping us Master the Web. My family and friends for enduring my voluntary financial hardship while pursuing my passions.