Initial commit: WooCommerce Email Discount Manager plugin

This commit is contained in:
kristianwind
2026-08-23 15:38:14 +02:00
commit e4a40e53a0
16 changed files with 4391 additions and 0 deletions
+236
View File
@@ -0,0 +1,236 @@
/* WooCommerce Email Discount Manager — admin styles */
.wc-edm-wrap .wc-edm-content {
margin-top: 20px;
}
/* Header row with title + primary action */
.wc-edm-header-row {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 12px;
}
.wc-edm-header-row h2 {
margin: 0;
}
/* Dashboard stat cards */
.wc-edm-stats {
display: flex;
flex-wrap: wrap;
gap: 16px;
margin: 8px 0 24px;
}
.wc-edm-stat-card {
background: #fff;
border: 1px solid #c3c4c7;
border-radius: 4px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
padding: 20px 28px;
min-width: 180px;
display: flex;
flex-direction: column;
gap: 4px;
}
.wc-edm-stat-number {
font-size: 32px;
font-weight: 600;
line-height: 1.2;
color: #1d2327;
}
.wc-edm-stat-label {
color: #646970;
font-size: 13px;
}
.wc-edm-quick-actions .button {
margin-right: 8px;
}
/* Tables */
.wc-edm-table {
max-width: 1100px;
}
.wc-edm-table .wc-edm-actions-col {
width: 150px;
text-align: right;
}
.wc-edm-table .wc-edm-actions-col .button {
margin-left: 4px;
}
/* Badges */
.wc-edm-badge {
display: inline-block;
padding: 2px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: 600;
line-height: 1.6;
background: #f0f0f1;
color: #3c434a;
}
.wc-edm-badge-percent,
.wc-edm-badge-group {
background: #e5f1e8;
color: #00450c;
}
.wc-edm-badge-coupon {
background: #fcf0e4;
color: #8a4d00;
}
.wc-edm-badge-custom {
background: #e6f0fa;
color: #0a4b78;
}
.wc-edm-badge-denied {
background: #fcebeb;
color: #8a2424;
}
/* Audit log */
.wc-edm-audit-table code {
background: #f0f0f1;
padding: 1px 5px;
border-radius: 3px;
font-size: 12px;
}
.wc-edm-audit-table .wc-edm-item-meta {
display: block;
color: #646970;
font-size: 12px;
margin-top: 2px;
}
/* Active / inactive status */
.wc-edm-status {
text-decoration: none;
font-weight: 600;
}
.wc-edm-status.is-active {
color: #00a32a;
}
.wc-edm-status.is-inactive {
color: #d63638;
}
.wc-edm-status:hover {
text-decoration: underline;
}
/* Sortable lists (categories + shipping methods) */
.wc-edm-sortable {
margin: 12px 0 4px;
max-width: 700px;
}
.wc-edm-sortable li {
display: flex;
align-items: center;
gap: 10px;
background: #fff;
border: 1px solid #c3c4c7;
border-radius: 4px;
padding: 8px 12px;
margin-bottom: 6px;
cursor: default;
}
.wc-edm-sortable .wc-edm-drag-handle {
color: #787c82;
cursor: move;
flex: 0 0 auto;
}
.wc-edm-sortable .wc-edm-item-label {
flex: 1 1 auto;
}
.wc-edm-sortable .wc-edm-item-meta {
display: block;
color: #646970;
font-size: 12px;
}
.wc-edm-sortable-placeholder {
border: 1px dashed #8c8f94;
border-radius: 4px;
background: #f6f7f7;
margin-bottom: 6px;
visibility: visible !important;
}
/* Remove-category button */
.wc-edm-remove-category {
flex: 0 0 auto;
border: none;
background: none;
color: #d63638;
font-size: 18px;
line-height: 1;
cursor: pointer;
padding: 0 4px;
}
.wc-edm-remove-category:hover {
color: #8a2424;
}
/* Category picker */
.wc-edm-category-picker {
display: flex;
align-items: center;
gap: 8px;
}
/* Shipping rules */
.wc-edm-group-selector {
margin: 16px 0;
display: flex;
align-items: center;
gap: 8px;
}
.wc-edm-shipping-list {
max-width: 900px;
}
.wc-edm-rule-options {
flex: 0 0 auto;
display: flex;
gap: 16px;
white-space: nowrap;
}
.wc-edm-rule-options label {
display: inline-flex;
align-items: center;
gap: 4px;
}
@media screen and (max-width: 782px) {
.wc-edm-sortable li {
flex-wrap: wrap;
}
.wc-edm-rule-options {
width: 100%;
padding-left: 30px;
}
}
+87
View File
@@ -0,0 +1,87 @@
/**
* WooCommerce Email Discount Manager — admin scripts.
*/
( function( $ ) {
'use strict';
$( function() {
// ---------------------------------------------------------------
// Drag & drop sorting (categories + shipping methods).
// ---------------------------------------------------------------
$( '.wc-edm-sortable' ).sortable( {
handle: '.wc-edm-drag-handle',
axis: 'y',
placeholder: 'wc-edm-sortable-placeholder',
forcePlaceholderSize: true
} );
// ---------------------------------------------------------------
// Group edit: add / remove categories.
// ---------------------------------------------------------------
var $categorySelect = $( '#wc-edm-category-select' );
var $categoryList = $( '#wc-edm-selected-categories' );
$( '#wc-edm-add-category' ).on( 'click', function() {
var $option = $categorySelect.find( 'option:selected' );
var id = $option.val();
var name = $option.text().trim();
if ( ! id || $option.prop( 'disabled' ) ) {
return;
}
var $item = $( '<li>' )
.attr( 'data-id', id )
.append( $( '<span>' ).addClass( 'dashicons dashicons-menu wc-edm-drag-handle' ) )
.append( $( '<span>' ).addClass( 'wc-edm-item-label' ).text( name ) )
.append( $( '<button>' ).attr( 'type', 'button' ).addClass( 'wc-edm-remove-category' ).html( '&times;' ) )
.append( $( '<input>' ).attr( { type: 'hidden', name: 'category_ids[]' } ).val( id ) );
$categoryList.append( $item );
$option.prop( 'disabled', true );
$categorySelect.val( '' );
} );
$categoryList.on( 'click', '.wc-edm-remove-category', function() {
var $item = $( this ).closest( 'li' );
var id = String( $item.data( 'id' ) );
$categorySelect.find( 'option[value="' + id + '"]' ).prop( 'disabled', false );
$item.remove();
} );
// ---------------------------------------------------------------
// Email edit: toggle fields for the selected assignment type.
// ---------------------------------------------------------------
function toggleAssignmentFields() {
var type = $( '#wc-edm-assignment-type input[name="assignment_type"]:checked' ).val();
$( '.wc-edm-type-fields' ).each( function() {
$( this ).toggle( $( this ).data( 'type' ) === type );
} );
}
if ( $( '#wc-edm-assignment-type' ).length ) {
toggleAssignmentFields();
$( '#wc-edm-assignment-type' ).on( 'change', 'input[name="assignment_type"]', toggleAssignmentFields );
}
// ---------------------------------------------------------------
// Confirm before deleting.
// ---------------------------------------------------------------
$( document ).on( 'click', '.wc-edm-delete', function( e ) {
if ( ! window.confirm( wcEdmAdmin.confirmDelete ) ) {
e.preventDefault();
}
} );
// ---------------------------------------------------------------
// Shipping tab: auto-submit the group selector on change.
// ---------------------------------------------------------------
$( '#wc-edm-shipping-group' ).on( 'change', function() {
$( this ).closest( 'form' ).trigger( 'submit' );
} );
} );
}( jQuery ) );