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.

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

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.

Latest Posts

Customize Lightbox Title Styling in the Divi Gallery Module

Adjust the appearance of the lightbox title that appears when visitors open images from a Divi Gallery to align with your brand and improve readability. Refining the title’s color, size, and weight enhances visual hierarchy, accessibility, and overall polish. In this...

Center the Lightbox Image Count in the Divi Gallery Module

Centering the image count in a gallery lightbox creates a cleaner, more balanced presentation and makes it easier for visitors to see where they are in the image set. This simple visual tweak can enhance readability, especially with larger images and longer captions,...

Style the Divi Gallery Module Lightbox Image Count

Tailor the appearance of the image counter in the Divi Gallery module lightbox to match your brand and improve readability. By customizing the counter’s color and typography, you ensure it displays clearly and suits your design. In this guide we show you how to style...

Customize the Lightbox Image Background Color in the Divi Gallery

Control the color that appears behind your images when users open in the gallery lightbox, including support for semi-transparent hues. This helps improve contrast for transparent images, align the experience with your brand palette, and create a more polished viewing...

Style the Divi Gallery Lightbox Close Button

Give your gallery lightbox a clear, on-brand close button by customizing its color and size. This improves visibility and usability against varying image backgrounds and ensures the button renders at full opacity for a consistent experience. In this guide we show you...

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 *.