Below, you’ll find a detailed guide on how to add the Wc Donation Platform Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Wc Donation Platform Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Wc Donation Platform Plugin and the shortcodes it provides:
"Donation Platform for WooCommerce: Fundraising & Donation Management is a robust plugin designed to seamlessly integrate fundraising and donation management features into your WooCommerce store."
- [wcdp_progress]
Wc Donation Platform [wcdp_progress] Shortcode
The ‘wcdp_progress’ shortcode from the wc-donation-platform plugin is used to display the progress of a fundraising campaign. It requires the ‘id’ attribute, representing the campaign ID. The ‘goal’ attribute represents the fundraising goal, which is set to 100 if not numeric. The ‘style’ attribute allows for different visual representations of the progress bar. Additional features include adding revenue from extra product IDs and a ‘cheat’ attribute to manually increase the revenue. The progress bar’s width is calculated as a percentage of the goal, with a maximum of 100%. The shortcode also supports custom styling and translations.
Shortcode: [wcdp_progress]
Parameters
Here is a list of all possible wcdp_progress shortcode parameters and attributes:
id
– The unique identifier of the donation.goal
– The set fundraiser goal amount.style
– Defines the style of the progress bar.addids
– Additional product IDs to include in the revenue.cheat
– A specific amount to add to the total revenue.
Examples and Usage
Basic example – Displaying the progress of a specific donation campaign using the campaign ID.
[wcdp_progress id=1 /]
Advanced examples
Displaying the progress of a specific donation campaign with a defined goal, using the campaign ID and goal parameter. The goal is set to 5000 in this example.
[wcdp_progress id=1 goal=5000 /]
Displaying the progress of a specific donation campaign with a custom style. The style is set to 2 in this example.
[wcdp_progress id=1 style=2 /]
Adding additional revenue to the progress of a specific donation campaign. The additional revenue is set to 500 in this example.
[wcdp_progress id=1 cheat=500 /]
Displaying the progress of multiple donation campaigns by using additional IDs. The additional IDs are 2 and 3 in this example.
[wcdp_progress id=1 addids="2,3" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wcdp_progress]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wcdp_progress', array($this, 'wcdp_progress'));
Shortcode PHP function:
function wcdp_progress(array $atts = array()) {
// Do not allow executing this Shortcode via AJAX
if (wp_doing_ajax()) return "";
if (!isset($atts['id'])) {
return esc_html__('wcdp_progress: Required attribute "id" missing.', 'wc-donation-platform');
}
$goal_db = get_post_meta( $atts['id'], 'wcdp-settings[wcdp_fundraising_goal]', true );
$end_date_db = get_post_meta( $atts['id'], 'wcdp-settings[wcdp_fundraising_end_date]', true );
$atts = shortcode_atts( array(
'id' => -1,
'goal' => $goal_db,
'style' => 1,
'addids' => '',
'cheat' => 0,
), $atts );
if (!is_numeric($atts['goal'])) {
$atts['goal'] = 100;
}
$revenue = (float) $this->getTotalRevenueOfProduct($atts['id']);
//Add revenue of additional Product IDs
$ids = explode(",", $atts['addids']);
foreach ($ids as $id) {
$revenue += (float) $this->getTotalRevenueOfProduct($id);
}
//Add specified amount to revenue
$revenue += (float) $atts['cheat'];
$revenue = apply_filters('wcdp_progress_revenue', $revenue, $atts);
if ((float) $atts['goal'] != 0) {
$width = ($revenue*100) / (float) $atts['goal'];
} else {
$width = 100;
}
if ($width > 100) {
$width = 100;
}
//Translators: %1$s: donation amount raised, %2$s: fundraising goal
$label = esc_html__('%1$s of %2$s', 'wc-donation-platform');
$template = '';
switch ($atts['style']) {
case 2:
$template = 'wcdp_progress_style_2.php';
break;
case 3:
$template = 'wcdp_progress_style_3.php';
break;
case 4:
$template = 'wcdp_progress_style_4.php';
break;
default:
$template = 'wcdp_progress_style_1.php';
}
ob_start(); ?>
<style>
<?php if (!defined('WCDP_PROGRESS_3') && !defined('WCDP_PROGRESS_2') && !defined('WCDP_PROGRESS_1')) : ?>
:root {
--wcdp-main: <?php echo sanitize_hex_color(get_option('wcdp_secondary_color', '#30bf76')); ?>;
--wcdp-main-2: <?php echo sanitize_hex_color(get_option('wcdp_main_color', '#00753a')); ?>;
--label-text-checked: white;
}
@keyframes wcdp-progress {
0% {
width: 0;
}
}
<?php endif;
include(WCDP_DIR . 'includes/templates/styles/progress/' . $template);
$r = ob_get_contents();
ob_end_clean();
return $r;
}
Code file location:
wc-donation-platform/wc-donation-platform/includes/class-wcdp-progress.php
Conclusion
Now that you’ve learned how to embed the Wc Donation Platform Plugin shortcode, 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