Replacing the Divi Pricing Table Button

Written by Dan Mossop

The Divi Theme's pricing table module allows you to add a button at the end of each pricing table item. The "button" is a really just a link, with text and a URL, styled to look like a button. So what if you need to replace it with something more complex, such as a form or button generated by a shortcode?

Tip: To use shortcodes within the pricing table fields (e.g. button text and link), try my Divi Shortcode Enabler plugin.

Filtering the Pricing Button HTML in PHP

One option is to modify the button HTML through PHP. Divi doesn't give us a way to do this directly. However, it does give us a way to modify the HTML for an entire pricing table item, using a WordPress "filter" called "et_pb_pricing_table_shortcode_output". We'll use this to first create a new filter, called "db_pricing_table_shortcode_output_button" which modifies just the button HTML:

// === Add "db_pricing_table_shortcode_output_button" filter ===

add_filter('et_pb_pricing_table_shortcode_output', 'dbcf_add_pricing_table_button_filter');

function dbcf_add_pricing_table_button_filter($html) {
	if (!is_admin() && !isset($_GET['et_fb'])) {
		$button_wrapper_regex = preg_quote('<div class="et_pb_button_wrapper">', '/').'.*?'.preg_quote('</div>', '/');
		$html = preg_replace_callback("/$button_wrapper_regex/s", 'dbcf_add_pricing_table_button_filter_callback', $html);
	}
	return $html;
}

function dbcf_add_pricing_table_button_filter_callback($match) {
	$button = isset($match[0])?$match[0]:'';
	return apply_filters('db_pricing_table_shortcode_output_button', $button);
}
This filter can now be used to modify the button HTML, and works in the same way as any other WordPress filter.

Example: Simple Membership Payment Button

The Simple Membership Payment plugin provides a way to create PayPal and Stripe payment buttons. These can be added to a page using the "swpm_payment_button" shortcode (described here). The output of the shortcode is a form – too complex to be implemented using the existing pricing table button. But we can use our new filter to replace the pricing table button with the output of the shortcode. like so:

add_filter('db_pricing_table_shortcode_output_button', 'dbcf_replace_pricing_table_button');

function dbcf_replace_pricing_table_button($button) {
	$swpm_button_regex = preg_quote('[swpm_payment_button', '/').'(.*?)'.preg_quote(']', '/');
	if (preg_match('/'.$swpm_button_regex.'/s', $button, $match)) {
		$swpm_button_shortcode = '[swpm_payment_button'.html_entity_decode($match[1]).']';	
		$swpm_button = do_shortcode($swpm_button_shortcode);
		$swpm_button = str_replace('class="swpm-buy-now-button-submit"', 'class="swpm-buy-now-button-submit et_pb_button et_pb_pricing_table_button"', $swpm_button);
		return $swpm_button;
	}
	return $button;
}

// Stop Divi Shortcode Enabler from processing the pricing table button URL if active
add_filter('dbdsp_fields_to_process', 'dbcf_stop_processing_of_shortcode_in_pricing_table');

function dbcf_stop_processing_of_shortcode_in_pricing_table($modules) {
	if (isset($modules['et_pb_pricing_table']['button_url'])) { 
		unset($modules['et_pb_pricing_table']['button_url']);
	}
	return $modules;
}
Now to use it:

  • Paste your payment button shortcode into the "Content > Text > Button" field of the pricing table – i.e. as the name of the button
  • Set the pricing table's "Content > Link > Button Link URL" field to "#" (so Divi actually displays the button).

The pricing table button should be replaced with the Simple Membership Plugin payment button. The code above also adds the pricing table button CSS classes to the payment button, so that it picks up (most of) the styles from the Divi pricing table button settings. A notable exception is that the button icons won't work (since they aren't supported on input elements such as used by the payment button). You may like to disable the button icon in the pricing table settings to prevent a blank space showing on the button on hover.

Unlock the Full Potential of Shortcodes in Divi!

Empower your Divi site with the Divi Shortcode Enabler. This plugin enables shortcodes to function in Divi module fields, perfect for customizing elements like pricing table buttons with advanced features.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.

Latest From Divi Booster

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Random Divi Posts