Shortcodes in pricing tables

Hi,

I wanted to have more control over the use of variable data like prices across my site. This is so that I don’t have to edit twenty places whenever this volatile info changes.

To do this I use a simple plugin that acts as a variable. I set the variable for, say, “myprice” to whatever the price is, and then use the shortcode whenever I need it (like this).

[get-variable id=“myprice”]

This works but when it comes to using the above in the text field for the price on the responsive pricing table element in the latest version of PRO, all I get is the exact text above, verbatim. In other words it does not recursively expand the shortcode.

Is there anything I can do here? If not, can you point me in the direction of your pricing table shortcode so that I can copy it and modify it?

Thanks
Steve

Hello Steve,

Thanks for the very detailed post information. What you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

After the child theme is set up, please add the following code in your child theme’s functions.php file

// Custom Pricing Table Column
// =============================================================================

function custom_x_shortcode_pricing_table_column( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'id'           => '',
    'class'        => '',
    'style'        => '',
    'featured'     => '',
    'featured_sub' => '',
    'title'        => '',
    'currency'     => '',
    'price'        => '',
    'interval'     => ''
  ), $atts, 'x_pricing_table_column' ) );

  $id           = ( $id    != ''        ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class        = ( $class != ''        ) ? 'x-pricing-column ' . esc_attr( $class ) : 'x-pricing-column';
  $style        = ( $style != ''        ) ? 'style="' . $style . '"' : '';
  $featured     = ( $featured == 'true' ) ? ' featured' : '';
  $featured_sub = ( $featured_sub != '' ) ? ' <span class="x-featured-sub">' . $featured_sub . '</span>' : '';
  $title        = ( $title != ''        ) ? $title : '';
  $currency     = ( $currency != ''     ) ? $currency : '';
  $price        = ( $price != ''        ) ? $price : '';
  $price        = do_shortcode( $price );
  $interval     = ( $interval != ''     ) ? $interval : '';

  $output = "<div {$id} class=\"{$class}{$featured}\" {$style}>"
            . '<h2 class="man">'
              . $title
              . $featured_sub
            . '</h2>'
            . '<div class="x-pricing-column-info">'
              . "<h3 class=\"x-price\">{$currency}{$price}</h3>"
              . "<span class=\"x-interval\">{$interval}</span>"
              . do_shortcode( $content )
            . '</div>'
          . '</div>';

  return $output;
}
add_action('wp_head', 'change_recent_posts_to_v2');

function change_recent_posts_to_v2() {
  remove_shortcode( 'cs_pricing_table_column', 'x_shortcode_pricing_table_column' );
  remove_shortcode( 'x_pricing_table_column', 'x_shortcode_pricing_table_column' );
  add_shortcode( 'cs_pricing_table_column', 'custom_x_shortcode_pricing_table_column' );
  add_shortcode( 'x_pricing_table_column', 'custom_x_shortcode_pricing_table_column' );
}

In the code above, I have modified it so that the price area will accept a shortcode.

Hope this helps. Kindly let us know.

Hi again,

Thanks for the quick reply and the additional code. I already had a child theme so adding this was easy.
However, unfortunately it doesn’t work.

I think the reason is this…

[cs_pricing_table_column title=“Basic” featured=“false” featured_sub=“For those on a budget” currency=“£” price="[shortcode-variables slug=“basic-price”]" class=“skyhawk-package skyhawk-package-basic”][cs_icon_list]

&lsqb;shortcode-variables slug=&quot;basic-price&quot;&rsqb;
vs.
[shortcode-variables slug=“basic-price”]

When saved, the price column converts the square brackets to HTML-friendly, so the shortcode mechanism is not kicking in.

Any suggestions?

Thanks
S.

Hi,

I’ve now resolved this…well, hacked it a bit. Probably not the best solution but it now works.
I’ve changed your code to add this:

function htmlspecialchars_decode_incl_sqb ($in)
{
	$out = htmlspecialchars_decode($in);
	$out = str_replace("&lsqb;","[",$out);
	$out = str_replace("&rsqb;","]",$out);
	return $out;
}

then altered the pricing table shortcode with this

...
  $price        = ( $price != ''        ) ? $price : '';
  $price        = do_shortcode( htmlspecialchars_decode_incl_sqb($price) );
...

(Sorry, I can’t figure out the best way to paste code into these messages).

I’m not a PHP expert so there’s probably better ways of doing this but it gets me working.

Thanks
S.

Glad you’ve sorted it out :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.