Skip to content

Instantly share code, notes, and snippets.

@jrstaatsiii
Created May 9, 2017 21:14
Show Gist options
  • Save jrstaatsiii/97ced2beb65ba759d7ddd807b71ebfe5 to your computer and use it in GitHub Desktop.
Save jrstaatsiii/97ced2beb65ba759d7ddd807b71ebfe5 to your computer and use it in GitHub Desktop.
Template Tag for SSM Pricing Tables
<?php
function pricing_plan_template( $plan, $display = 'full', $pricing_table_id ) {
$features = get_field('features', $pricing_table_id); // list or curated
if ( $features == 'list') {
$available_features = get_field('standard_feature_list', $pricing_table_id);
$standard_features = $plan['standard_features'];
} else {
$available_features = $plan['feature_list'];
}
// print_r( $plan );
$plan_id = strtolower($plan['plan_title']);
$plan_id = str_replace(' ', '_', $plan_id);
$plan_class = '';
$plan_has_sale = FALSE;
// TODO: Replace with options from settings page
$price_options = array( 'monthly', 'quarterly', 'yearly' );
$currency = '$';
$sale_array = array();
foreach ( $price_options as $option ) {
if ( $plan[ $option . '_sale_price'] != NULL ) {
$sale_array[] = $option . '_sale_price' ;
}
}
if ( $display == 'condensed' ) {
$plan_class = ' condensed';
}
if ( !empty( $sale_array )) {
$plan_class .= ' has-sale';
$plan_has_sale = TRUE;
}
$html = '<div class="pricing-plan small-12 medium-expand column' . $plan_class . '">';
$html .= '<div class="inner" data-equalizer-watch>';
$html .= '<header class="pricing-plan-header">';
$html .= '<h3 class="title">' . $plan['plan_title'] . '</h3>';
$html .= '<p class="description">' . $plan['plan_description'] . '</p>';
$html .= '</header>';
if ( $price_options ) {
$html .= '<div class="price-options">';
$html .= '<div class="regular-price-wrap">';
foreach ( $price_options as $option ) {
if ( $plan[ $option . '_price' ] ) {
$html .= '<h4 class="regular-price ' . $option . '">';
if ( $plan[ $option . '_sale_price' ] ) {
$html .= '<span class="strikethrough">';
}
$html .= '<sup>' . $currency . '</sup><span id="' . $plan_id . '_' . $option . '" class="price">' . $plan[ $option . '_price' ] . '</span> ' . $option;
if ( $plan[ $option . '_sale_price' ] ) {
$html .= '</span>';
}
$html .= '</h4>';
}
}
$html .= '</div>'; // end regular-price-wrap
if ( $plan_has_sale == TRUE ) {
$html .= '<div class="sale-price-wrap">';
foreach ( $price_options as $option ) {
if ( $plan[ $option . '_sale_price' ] ) {
$html .= '<h4 class="sale-price ' . $option . '"><sup>' . $currency . '</sup><strong><span id="' . $plan_id . '_' . $option . '" class="price">' . $plan[ $option . '_sale_price' ] . '</span></strong> ' . $option . '</h4>';
}
}
$html .= '</div>'; // end sale-price-wrap
} // endif $plan_has_sale
$html .= '</div>'; // end price-options
} // endif $price_options
if ( $display == 'full' && $available_features ) {
$html .= '<ul class="plan-features">';
foreach ( $available_features as $feature ) {
$class = '';
if ( $features == 'list' ) {
$class = in_array( $feature['feature'], $standard_features ) ? ' class="included"' : '';
}
$html .= '<li' . $class . '>' . $feature['feature'] . '</li>';
}
$html .= '</ul>';
}
if ( $display == 'condensed' ) {
$url = get_sub_field('pricing_page');
} else {
$url = $plan['button_url'];
}
$html .= '<div><a class="button button-blue" href="' . $url . '">' . $plan['button_text'] . '</a></div>';
$html .= '</div>'; // end inner
$html .= '</div>'; // end pricing-plan
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment