Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions assets/src/css/frontend-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
width: 100%;
}
}
.campaign-cause{
ul{
margin-bottom: 0;
}
p{
margin-bottom: 0;
}
}
.suggested-amounts {
display: grid;
grid-template-columns: repeat(4, 1fr);
Expand Down Expand Up @@ -69,3 +77,63 @@
align-self: center;
}
}
//Frontend donation progressbar
.wcdm-progress-bar {
width: 100%;
margin-bottom: 10px;
.donation-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}

.donation-title {
font-size: 16px;
font-weight: 700;
color: #1e293b;
}

.donation-percent {
font-size: 20px;
font-weight: 700;
background: #10B981;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

.progress-wrapper {
width: 100%;
height: 14px;
background: #e2e8f0;
border-radius: 999px;
overflow: hidden;
position: relative;
}

.progress-bar {
width: 0;
height: 100%;
border-radius: 999px;
transition: width 1s ease;

background:#10B981;
}

.donation-info {
display: flex;
justify-content: space-between;
margin-top: 14px;
font-size: 14px;
color: #64748b;
}

.amount {
font-weight: 700;
color: #0f172a;
}
}
//Donation product donation button
.wcdm-donation-button{
background-color: #10B981 !important;
}
36 changes: 35 additions & 1 deletion assets/src/js/admin-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Copyright (c) 2025 PluginEver
* Licensed under the GPLv2+ license.
*/
s
/*jslint browser: true */
/*global jQuery:false */
jQuery(document).ready(function ($) {
'use strict';

$.wc_donation_manager = {
init: function () {
$('#donation_products').select2({
Expand Down Expand Up @@ -45,4 +45,38 @@ jQuery(document).ready(function ($) {
};

$.wc_donation_manager.init();

// Helper function to show admin error
function wcdm_show_admin_error(message) {
$('.wcdm-admin-error').remove();
var $notice = $('<div class="notice notice-error is-dismissible wcdm-admin-error"><p>' + message + '</p></div>');
$('.wrap').first().prepend($notice);
$('html, body').animate({scrollTop: $('.wrap').first().offset().top - 50}, 200);
}

// Validate on product save
$('#post').on('submit', function (e) {
var prodType = $('#product-type').val() || $('select[name="product-type"]').val() || $('input[name="product-type"]').val();
if (prodType !== 'donation') return true;

var min = parseFloat($('#wcdm_min_amount').val());
var max = parseFloat($('#wcdm_max_amount').val());
min = isNaN(min) ? 0 : min;
max = isNaN(max) ? 0 : max;
var campaign = $('#wcdm_campaign_id').val() || $('select[name="wcdm_campaign_id"]').val();

if (!campaign || campaign === '0' || parseInt(campaign, 10) <= 0) {
e.preventDefault();
wcdm_show_admin_error((typeof wcdm_admin_vars !== 'undefined' && wcdm_admin_vars.i18n && wcdm_admin_vars.i18n.select_campaign_error) ? wcdm_admin_vars.i18n.select_campaign_error : 'Please select a campaign for donation products.');
return false;
}

if (min > 0 && max > 0 && min > max) {
e.preventDefault();
wcdm_show_admin_error((typeof wcdm_admin_vars !== 'undefined' && wcdm_admin_vars.i18n && wcdm_admin_vars.i18n.min_gt_max_error) ? wcdm_admin_vars.i18n.min_gt_max_error : 'Minimum amount cannot be greater than maximum amount.');
return false;
}

return true;
});
});
32 changes: 32 additions & 0 deletions assets/src/js/frontend-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,37 @@
}
});
});

$('.wcdm-progress-bar').each(function () {

const $progressCard = $(this);

const raised = parseFloat($progressCard.attr('data-raised')) || 0;
const goal = parseFloat($progressCard.attr('data-goal')) || 0;
const currency = $progressCard.attr('data-currency') || '$';

const percentage = goal > 0
? Math.min((raised / goal) * 100, 100)
: 0;

console.log(percentage);


$progressCard
.find('.progress-bar')
.css('width', percentage + '%');

$progressCard
.find('.donation-percent')
.text(Math.round(percentage) + '%');

$progressCard
.find('.raised-amount')
.text(currency + raised.toLocaleString());

$progressCard
.find('.goal-amount')
.text(currency + goal.toLocaleString());
});
});
}(jQuery));
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repositories": [
{
"type": "vcs",
"url": "git@github.com:byteever/bytekit-plugin.git"
"url": "git@github.com:byteever/plugin.git"
},
{
"type": "vcs",
Expand All @@ -14,7 +14,7 @@
],
"require": {
"php": ">=7.4",
"byteever/bytekit-plugin": "dev-trunk",
"byteever/plugin": "dev-trunk",
"byteever/bytekit-settings": "dev-trunk"
},
"require-dev": {
Expand Down Expand Up @@ -52,7 +52,7 @@
"namespace_prefix": "WooCommerceDonationManager\\",
"classmap_prefix": "WooCommerceDonationManager__",
"packages": [
"byteever/bytekit-plugin",
"byteever/plugin",
"byteever/bytekit-settings"
]
}
Expand Down
8 changes: 3 additions & 5 deletions includes/Admin/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @package WooCommerceDonationManager
*/
class Actions {

/**
* Actions constructor.
*
Expand All @@ -37,7 +36,7 @@ public static function add_campaign() {
$referer = wp_get_referer();

$name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
$cause = isset( $_POST['cause'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cause'] ) ) : '';
$cause = isset( $_POST['cause'] ) ? wp_kses_post( wp_unslash( $_POST['cause'] ) ) : '';
$goal_amount = isset( $_POST['goal_amount'] ) ? floatval( wp_unslash( $_POST['goal_amount'] ) ) : floatval( '0' );
$end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : '';
$status = isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : 'pending';
Expand All @@ -47,7 +46,7 @@ public static function add_campaign() {
'ID' => $id,
'post_type' => 'wcdm_campaigns',
'post_title' => wp_strip_all_tags( $name ),
'post_content' => wp_kses_post( $cause ),
'post_content' => $cause,
'post_status' => $status,
'meta_input' => array(
'wcdm_goal_amount' => $goal_amount,
Expand Down Expand Up @@ -83,7 +82,7 @@ public static function edit_campaign() {
$referer = wp_get_referer();

$name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
$cause = isset( $_POST['cause'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cause'] ) ) : '';
$cause = isset( $_POST['cause'] ) ? wp_kses_post( wp_unslash( $_POST['cause'] ) ) : '';
$goal_amount = isset( $_POST['goal_amount'] ) ? floatval( wp_unslash( $_POST['goal_amount'] ) ) : floatval( '0' );
$end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : '';
$status = isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : 'pending';
Expand All @@ -108,7 +107,6 @@ public static function edit_campaign() {
} else {
WCDM()->flash->success( __( 'Campaign updated successfully.', 'wc-donation-manager' ) );
}

wp_safe_redirect( $referer );
exit;
}
Expand Down
46 changes: 30 additions & 16 deletions includes/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WooCommerceDonationManager\Admin;

use WooCommerceDonationManager\Plugin;

defined( 'ABSPATH' ) || exit; // Exit if accessed directly.

/**
Expand All @@ -11,13 +13,22 @@
* @package WooCommerceDonationManager\Admin
*/
class Admin {
/**
* Plugin instance.
*
* @var Plugin
*/
protected Plugin $plugin;

/**
* Admin constructor.
* Admin Class constructor.
*
* @since 1.0.0
*
* @param Plugin $plugin Plugin instance.
*/
public function __construct() {
public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'woocommerce_screen_ids', array( $this, 'add_screen_ids' ) );
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), PHP_INT_MAX );
Expand All @@ -32,20 +43,23 @@ public function __construct() {
* @since 1.0.0
* @return void
*/
public function enqueue_scripts( $hook ) {
public function enqueue_scripts( $hook ): void {
$screen_ids = Utilities::get_screen_ids();
WCDM()->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'bytekit-layout', 'bytekit-components', 'woocommerce_admin_styles' ) );
WCDM()->scripts->register_script( 'wcdm-admin', 'js/admin.js' );
$this->plugin->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'bytekit-layout', 'bytekit-components', 'woocommerce_admin_styles' ) );
$this->plugin->scripts->register_script( 'wcdm-admin', 'js/admin.js' );

if ( in_array( $hook, $screen_ids, true ) || 'post-new.php' === $hook ) {

if ( in_array( $hook, $screen_ids, true ) ) {
wp_enqueue_style( 'wcdm-admin' );
wp_enqueue_script( 'wcdm-admin' );

$localize = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'security' => wp_create_nonce( 'wc_donation_manager' ),
'i18n' => array(
'search_products' => esc_html__( 'Select products', 'wc-donation-manager' ),
'search_products' => esc_html__( 'Select products', 'wc-donation-manager' ),
'select_campaign_error' => esc_html__( 'Please select a campaign for donation products.', 'wc-donation-manager' ),
'min_gt_max_error' => esc_html__( 'Minimum amount cannot be greater than maximum amount.', 'wc-donation-manager' ),
),
);

Expand All @@ -61,7 +75,7 @@ public function enqueue_scripts( $hook ) {
*
* @return array
*/
public function add_screen_ids( $ids ) {
public function add_screen_ids( $ids ): array {
return array_merge( $ids, Utilities::get_screen_ids() );
}

Expand All @@ -70,22 +84,22 @@ public function add_screen_ids( $ids ) {
*
* @param string $text Footer text.
*
* @since 1.0.0
* @return string
* @since 1.0.0
*/
public function admin_footer_text( $text ) {
public function admin_footer_text( string $text ): string {

if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) {
$text = sprintf(
/* translators: %s: Plugin name */
__( 'Thank you for using %s!', 'wc-donation-manager' ),
'<strong>' . esc_html( WCDM()->get_name() ) . '</strong>',
'<strong>' . esc_html__( 'Donation Manager', 'wc-donation-manager' ) . '</strong>',
);
if ( WCDM()->get_review_url() ) {
if ( $this->plugin->review_url ) {
$text .= sprintf(
/* translators: %s: Plugin name */
__( ' Share your appreciation with a five-star review %s.', 'wc-donation-manager' ),
'<a href="' . esc_url( WCDM()->get_review_url() ) . '" target="_blank">here</a>'
'<a href="' . esc_url( $this->plugin->review_url ) . '" target="_blank">here</a>'
);
}
}
Expand All @@ -98,14 +112,14 @@ public function admin_footer_text( $text ) {
*
* @param string $text Footer text.
*
* @since 1.0.0
* @return string
* @since 1.0.0
*/
public function update_footer( $text ) {
public function update_footer( string $text ): string {

if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) {
/* translators: 1: Plugin version */
$text = sprintf( esc_html__( 'Version %s', 'wc-donation-manager' ), WCDM()->get_version() );
$text = sprintf( esc_html__( 'Version %s', 'wc-donation-manager' ), $this->plugin->version );
}

return $text;
Expand Down
Loading
Loading