Stylish Cost Calculator Shortcodes

Below, you’ll find a detailed guide on how to add the Stylish Cost Calculator Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Stylish Cost Calculator Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Stylish Cost Calculator Plugin and the shortcodes it provides:

Plugin Icon
Stylish Cost Calculator – Quote Generator, Lead Gen & Price Estimator

"Stylish Cost Calculator is a versatile WordPress plugin designed for quote generation, lead generation, and price estimation. With its user-friendly interface, it simplifies complex costing processes."

★★★★☆ (145) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [scc_calculator]
  • [scc_calculator-total]

Stylish Cost Calculator [scc_calculator] Shortcode

The Stylish Cost Calculator shortcode generates a dynamic and interactive price estimation form on your WordPress site. It pulls data from the database, applies conditions, and renders the form with Google Fonts and custom styles. It also handles invalid calculator ID errors, ensuring smooth user experience.

Shortcode: [scc_calculator]

Parameters

Here is a list of all possible scc_calculator shortcode parameters and attributes:

  • idvalue – Identifier of the calculator form to be displayed

Examples and Usage

Basic example – Display a stylish cost calculator on your page by referencing the calculator’s ID.

[scc_calculator idvalue=1 /]

Advanced examples

Display a stylish cost calculator on your page by referencing the calculator’s ID, and add additional parameters to customize the display and functionality of the calculator.

[scc_calculator idvalue=2 param1=value1 param2=value2 /]

Note: In the above example, replace ‘param1’ and ‘param2’ with the actual parameter names, and ‘value1’ and ‘value2’ with the desired values for those parameters. The actual parameters and their possible values depend on the configuration options provided by the stylish cost calculator plugin.

For instance, you might have parameters to control the display style of the calculator, the currency used for cost calculations, or the behavior of the calculator when a user interacts with it. Consult the documentation of the stylish cost calculator plugin for a complete list of available parameters and their possible values.

PHP Function Code

In case you have difficulties debugging what causing issues with [scc_calculator] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'scc_calculator', [ $this, 'scc_shortcode1' ] );

Shortcode PHP function:

function scc_shortcode1( $atts ) {
        if ( ! is_admin() ) {
            add_action(
                'wp_footer',
                function () {
                    require SCC_DIR . '/admin/views/modalTemplates.php';
                }
            );
            //wp_localize_script( 'scc-frontend', 'pageCalcFront' . intval( $atts['idvalue'] ), array( 'nonce' => wp_create_nonce( 'calculator-front-page' . intval( $atts['idvalue'] ) ) ) );
            $data       = [ 'nonce' => wp_create_nonce( 'calculator-front-page' . intval( $atts['idvalue'] ) ) ];
            $calc_id    =  intval( $atts['idvalue'] );
            $array_data = json_encode( $data );
            add_action( 'wp_footer', function () use ( $calc_id, $array_data ) {
                printf( '<script type="text/javascript">var pageCalcFront%s = %s</script>', $calc_id, $array_data );
            } );
        }
        wp_enqueue_style( 'scc-admin-style' );
        wp_enqueue_style( 'scc-checkbox1' );
        wp_enqueue_style( 'scc-tom-select' );
        wp_enqueue_script( 'scc-tom-select' );
        wp_enqueue_style( 'scc-bootstrapslider-css' );
        wp_enqueue_script( 'scc-bootstrapslider-js' );
        wp_enqueue_script( 'scc-frontend' );
        wp_enqueue_script( 'scc-nouislider' );
        wp_enqueue_script( 'wp-util' );
        wp_enqueue_script( 'scc-translate-js' );
        wp_enqueue_script( 'scc-bootstrap-min3' );

        /* $currencies_array = 'window["scc_currencies"] = ' . json_encode(
            require_once( SCC_DIR . '/lib/currency_data.php' )
        );
        wp_add_inline_script( 'scc-frontend', $currencies_array ); */

        if ( ! function_exists( 'scc_currency_array_script' ) ) {
            function scc_currency_array_script() {
                $currencies_array = 'window["scc_currencies"] = ' . json_encode( require SCC_DIR . '/lib/currency_data.php' );
                echo '<script type="text/javascript">' . $currencies_array . '</script>';
            }
        }
        add_action( 'wp_footer', 'scc_currency_array_script' );

        ob_start();
        extract(
            shortcode_atts(
                [
                    'idvalue' => null,
                ],
                $atts,
                'bt_cc_item'
            )
        );

        if ( ! function_exists( 'get' ) ) {
            function get( $id ) {
                global $wpdb;
                $scc_form = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}df_scc_forms WHERE id =%d ;", $id ) );

                if ( $scc_form ) {
                    $scc_form->turnoffemailquote = true;
                    $scc_form->turnoffcoupon     = true;
                    $form_id                     = $scc_form->id;
                    $sections                    = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}df_scc_sections WHERE form_id =%d ORDER By `order`;", $form_id ) );
                    $scc_form->sections          = $sections;

                    foreach ( $sections as $section ) {
                        $section_id          = $section->id;
                        $subsection          = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}df_scc_subsections WHERE section_id =%d ;", $section_id ) );
                        $section->subsection = $subsection;

                        foreach ( $section->subsection as $sub ) {
                            $sub_id       = $sub->id;
                            $elements     = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}df_scc_elements WHERE subsection_id =%d ORDER By orden +0; ", $sub_id ) );
                            $sub->element = $elements;

                            foreach ( $sub->element as $el2 ) {
                                $elem_id         = $el2->id;
                                $condition       = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}df_scc_conditions WHERE element_id =%d ;", $elem_id ) );
                                $el2->conditions = $condition;

                                foreach ( $el2->conditions as $c ) {
                                    if ( $c->elementitem_id ) {
                                        $element             = $wpdb->get_row( $wpdb->prepare( "SELECT `name` FROM {$wpdb->prefix}df_scc_elementitems WHERE id =%d ;", $c->elementitem_id ) );
                                        $c->elementitem_name = $element;
                                    }

                                    if ( $c->condition_element_id ) {
                                        $element              = $wpdb->get_row( $wpdb->prepare( "SELECT `titleElement`,`type` FROM {$wpdb->prefix}df_scc_elements WHERE id =%d ;", $c->condition_element_id ) );
                                        $c->element_condition = $element;
                                    }
                                }
                            }

                            foreach ( $sub->element as $el ) {
                                $elem_id  = $el->id;
                                $elements = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}df_scc_elementitems WHERE element_id =%d ;", $elem_id ) );
                                // change 'price' property of element to zero if it is an empty string value, so it doesn't return javascript NaN value
                                $elements         = array_map(
                                    function ( $e ) {
                                        if ( $e->price == '' ) {
                                            $e->price = 0;
                                        }

                                        return $e;
                                    },
                                    $elements
                                );
                                $el->elementitems = $elements;
                            }
                        }
                    }

                    return $scc_form;
                }
            }
        }
        require SCC_DIR . '/lib/wp-google-fonts/google-fonts.php';
        $form = get( $idvalue );

        if ( ! $form ) {
            return "<h4 style='color:red'>Invalid calculator with ID {$atts['idvalue']}</h4>";
        }
        $form->showFieldsQuoteArray = json_decode( stripslashes( $form->showFieldsQuoteArray ), true );
        $allfonts2                  = json_decode( $scc_googlefonts_var->gf_get_local_fonts() );
        $allfonts2i                 = $allfonts2->items;
        $fontUsed2                  = ! empty( $form->titleFontType ) ? $allfonts2i[ $form->titleFontType ] : null;
        $fontUsed2Variant           = ( $form->titleFontWeight != '' ) ? $form->titleFontWeight : 'regular';
        $google_font_links          = [];
        /**
         *Title font
         */
        $fontFamilyService2 = 'inherit';
        $fontFamilyTitle2   = 'inherit';
        // always set font types to inherit on free copy
        $form->inheritFontType = 'true';

        if ( $form->inheritFontType == 'null' || $form->inheritFontType == 'false' ) {
            $fonts[0]['kind']     = $fontUsed2->kind;
            $fonts[0]['family']   = $fontUsed2->family;
            $fonts[0]['variants'] = [ $fontUsed2Variant ];
            $fonts[0]['subsets']  = $fontUsed2->subsets;
            $fontFamilyTitle2     = $fonts[0]['family'];
            $font_link            = $scc_googlefonts_var->style_late( $fonts );
            array_push( $google_font_links, $font_link ); //load google fonts css
        }
        /**
         *Service font
         */
        $allfonts3i       = $allfonts2->items;
        $fontUsed3        = ! empty( $form->fontType ) ? $allfonts3i[ $form->fontType ] : null;
        $fontUsed3Variant = ( $form->fontWeight != '' ) ? $form->fontWeight : 'regular';

        if ( $form->inheritFontType == 'null' || $form->inheritFontType == 'false' ) {
            $fonts2[0]['kind']     = $fontUsed3->kind;
            $fonts2[0]['family']   = $fontUsed3->family;
            $fonts2[0]['variants'] = [ $fontUsed3Variant ];
            $fonts2[0]['subsets']  = $fontUsed3->subsets;
            $fontFamilyService2    = $fonts2[0]['family'];
            $font_link             = $scc_googlefonts_var->style_late( $fonts );
            array_push( $google_font_links, $font_link ); //load google fonts css
        }
        /**
         *Object font
         */
        $colorObject                   = $form->objectColorPicker;
        $currency_style                = get_option( 'df_scc_currency_style', 'default' ); // dot or comma
        $currency                      = get_option( 'df_scc_currency', 'USD' );
        $currency_conversion_mode      = get_option( 'df_scc_currency_coversion_mode', 'off' );
        $currency_conversion_selection = get_option( 'df_scc_currency_coversion_manual_selection' );
        require SCC_DIR . '/admin/views/generateFrontendForm.php';

        return ob_get_clean();
    }

Code file location:

stylish-cost-calculator/stylish-cost-calculator/stylish-cost-calculator.php

Stylish Cost Calculator [scc_calculator-total] Shortcode

The Stylish Cost Calculator shortcode is a powerful tool for creating dynamic, customizable cost calculators on your WordPress site. This shortcode allows you to define a total cost calculator with customizable attributes such as ‘idvalue’, ‘combine’, ‘currency-symbol’, ‘prefix-text’, and ‘apply-math’. The ‘idvalue’ attribute sets the calculator’s ID, while ‘combine’ enables combining multiple calculator values. The ‘currency-symbol’ allows you to set the currency for the total cost, ‘prefix-text’ adds a text before the total, and ‘apply-math’ applies mathematical operations to the total. This shortcode provides flexibility in presenting cost calculations to your site visitors, enhancing user experience.

Shortcode: [scc_calculator-total]

Parameters

Here is a list of all possible scc_calculator-total shortcode parameters and attributes:

  • idvalue – Specifies the unique identifier of the calculator.
  • combine – If set, idvalue is ignored and values are combined instead.
  • currency-symbol – Decides if currency symbol is displayed, 0 is for no, 1 is for yes.
  • prefix-text – Text to display before the total value.
  • apply-math – Defines the mathematical operation to apply, either “add” or “subtract”.

Examples and Usage

Basic example – Displaying a calculator total with a specific ID

[scc_calculator-total idvalue=5 /]

In this example, we are using the ‘scc_calculator-total’ shortcode to display the total of the calculator with the ID of 5. The ‘idvalue’ attribute is used to specify the ID of the calculator.

Advanced examples

Displaying a calculator total with a specific ID and a prefix text

[scc_calculator-total idvalue=5 prefix-text="Total: " /]

In this advanced example, we are not only displaying the total of the calculator with the ID of 5 but also adding a prefix text “Total: ” before the total. The ‘prefix-text’ attribute is used to specify the text that will be displayed before the total.

Combining multiple calculator totals with a specific currency symbol

[scc_calculator-total combine="5,6,7" currency-symbol=1 /]

In this advanced example, we are combining the totals of the calculators with the IDs 5, 6, and 7. We are also specifying the currency symbol to be used with the ‘currency-symbol’ attribute. The ‘combine’ attribute is used to specify the IDs of the calculators whose totals will be combined. The IDs are separated by commas.

PHP Function Code

In case you have difficulties debugging what causing issues with [scc_calculator-total] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'scc_calculator-total', [ $this, 'create_scc_total_tag' ] );

Shortcode PHP function:

function create_scc_total_tag( $attributes ) {
        // parse the attribute, if not supplied, default value is set
        $attributes = shortcode_atts(
            [
                'idvalue'         => 0,
                'combine'         => 0,
                'currency-symbol' => 0,
                'prefix-text'     => '',
                'apply-math'      => 0,
            ],
            $attributes
        );
        // $prefixText and $mathParams holds the array data to a variable
        $prefixText = $attributes['prefix-text'];
        $mathParams = $attributes['apply-math'] ? json_encode( explode( ':', $attributes['apply-math'] ) ) : '["add","0"]';
        // if combine attribute is there, idvalue does not work
        if ( $attributes['idvalue'] && ! ( $attributes['combine'] ) ) {
            $calculatorId = absint( $attributes['idvalue'] );
            $html         = "<span class=\"scc-multiple-total-wrapper calcid-$calculatorId\" data-math={$mathParams}>
    <span>$prefixText</span>
    <span class=\"multi-total-currency-prefix\"></span>
    <span class=\"scc-total\">0</span>
    <span class=\"multi-total-currency-suffix\"></span>
    </span>";
        }
        // if there is combine attribute, this html is printed
        if ( $attributes['combine'] ) {
            $ourFormula     = $attributes['combine'];
            $currencySymbol = isset( $attributes['currency-symbol'] ) ? absint( $attributes['currency-symbol'] ) : 1;
            $calcValues     = explode( ',', $ourFormula );

            if ( ! empty( $calcValues ) && count( $calcValues ) > 1 ) {
                $calcValues = json_encode( $calcValues );
                $html       = "<span class=\"scc-multiple-total-wrapper scc-combination\" data-combination={$calcValues} data-curr-sym={$currencySymbol} data-math={$mathParams}>
      <span>$prefixText</span>
      <span class=\"multi-total-currency-prefix\"></span>
      <span class=\"scc-total\"></span>
      <span class=\"multi-total-currency-suffix\"></span>
      </span>";
            }
        }

        return $html;
    }

Code file location:

stylish-cost-calculator/stylish-cost-calculator/stylish-cost-calculator.php

Conclusion

Now that you’ve learned how to embed the Stylish Cost Calculator Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

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