Below, you’ll find a detailed guide on how to add the Coupon & Discount Code Reveal Button 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 Coupon & Discount Code Reveal Button Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Coupon & Discount Code Reveal Button Plugin and the shortcodes it provides:
"Coupon & Discount Code Reveal Button is a powerful WordPress plugin that adds an engaging reveal button for discounts and coupons on your site, enhancing shopping experiences."
- [spbcta_sc]
- [spbcta_sc_all]
Coupon & Discount Code Reveal Button [spbcta_sc] Shortcode
The Coupon Reveal Button shortcode is designed to generate a button that reveals a coupon code. It fetches data from the database based on the ‘id’ attribute. The code generates a button with custom styles, text, and link. The button’s appearance and functionality can be customized using the attributes. If the ‘ureveal’ attribute is set, a hidden content area is created, revealing the last three characters of the coupon code when clicked.
Shortcode: [spbcta_sc]
Parameters
Here is a list of all possible spbcta_sc shortcode parameters and attributes:
id
– A unique identifier for the specific button
Examples and Usage
Basic example – A simple shortcode usage to display a coupon reveal button by referencing the ID
[spbcta_sc id=1 /]
Advanced examples
Using the shortcode to display a coupon reveal button by referencing the ID. The button will first try to load by ID, but if not found, it will not display anything.
[spbcta_sc id=2 /]
Another advanced usage of the shortcode can be to display multiple coupon reveal buttons by referencing their IDs. This will display buttons for the IDs that are found in the database.
[spbcta_sc id=3 /]
[spbcta_sc id=4 /]
Please note that the shortcode will not display anything if the ID is not found in the database. Also, the ID should be a positive integer.
PHP Function Code
In case you have difficulties debugging what causing issues with [spbcta_sc]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('spbcta_sc', array($this, 'spbcta_handleSC'));
Shortcode PHP function:
function spbcta_handleSC($atts)
{
// Attributes
$atts = shortcode_atts(
array(
'id' => '',
),
$atts,
'spbcta_sc'
);
if (!$atts['id']) {
return;
}
$table = $this->db->get((int)$atts['id']);
if ($table) {
$CTAId = (int)$atts['id'];
$CTAColor = $table['color'];
$CTAStyle = $table['style'] ? $table['style'] : 'simple';
$CTAutext = $table['utext'];
$CTAureveal = $table['ureveal'];
$CTAlink = $table['link'];
if (!$CTAlink) {
$CTAlink = '#spbcta_ph'.$CTAId;
}
$CTABlank = (int)$table['blank'];
ob_start(); ?>
<div class="reveal__button__wrapper reveal__button__<?php echo esc_attr($CTAStyle); ?>__design">
<!-- Coupon Reveal Button plugin -->
<a id="spbcta<?php echo $CTAId?>" href="<?php echo esc_url($CTAlink); ?>" <?php if ($CTABlank == 1) {?>target="_blank"<?php } ?> class="reveal__button__link" onclick="spbctaNM.func.spbcta_pass('<?php echo base64_encode(esc_attr($CTAureveal)); ?>',this,'<?php echo esc_url($CTAlink); ?>',<?php echo $CTABlank ?>);">
<span class="reveal__button__text" style="background:<?php echo $CTAColor[0]?> !important; color:<?php echo $CTAColor[1]?> !important;"><?php echo esc_attr($CTAutext); ?></span>
<?php if ($CTAureveal) { ?><span class="reveal__button__hidden__content" style="color:<?php echo $CTAColor[3]?> !important;border:dotted 2px <?php echo $CTAColor[4]?> !important;background-color:<?php echo $CTAColor[2]?> !important;"><?php echo mb_substr(esc_attr($CTAureveal), -3) ?></span><?php } ?>
</a>
</div>
<?php
return ob_get_clean();
}
}
Code file location:
coupon-reveal-button/coupon-reveal-button/inc/spbcta-plugin.php
Coupon & Discount Code Reveal Button [spbcta_sc_all] Shortcode
The ‘spbcta_sc_all’ shortcode from the coupon-reveal-button plugin retrieves all buttons from the database. It loops through each button and executes each one’s specific shortcode.
Shortcode: [spbcta_sc_all]
Parameters
Here is a list of all possible spbcta_sc_all shortcode parameters and attributes:
id
– Unique ID assigned to each button
Examples and Usage
Basic example – Showcases how to use the shortcode to display a single button by referencing its ID.
[spbcta_sc id=1 /]
Advanced examples
Illustrates the use of the shortcode to display multiple buttons by referencing their IDs. The buttons will load in the order of the IDs provided.
[spbcta_sc id=1 /]
[spbcta_sc id=2 /]
[spbcta_sc id=3 /]
Demonstrates the usage of the shortcode to display all the buttons. This is achieved by using the ‘spbcta_sc_all’ shortcode without any parameters.
[spbcta_sc_all /]
PHP Function Code
In case you have difficulties debugging what causing issues with [spbcta_sc_all]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('spbcta_sc_all', array($this, 'spbcta_handleSC_all'));
Shortcode PHP function:
function spbcta_handleSC_all()
{
$buttons = $this->db->get_all();
if ($buttons !== false && count($buttons) > 0) {
ob_start();
foreach ($buttons as &$single_button) {
echo do_shortcode('[spbcta_sc id='.$single_button['id'].']');
}
return ob_get_clean();
}
return;
}
Code file location:
coupon-reveal-button/coupon-reveal-button/inc/spbcta-plugin.php
Conclusion
Now that you’ve learned how to embed the Coupon & Discount Code Reveal Button 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.
Leave a Reply