roles);
$is_admin = current_user_can('manage_options');
if ($is_admin) {
// Full admin menus
add_submenu_page(
'edit.php?post_type=wpdd_product',
__('Orders', 'wp-digital-download'),
__('Orders', 'wp-digital-download'),
'wpdd_manage_orders',
'wpdd-orders',
array(__CLASS__, 'render_orders_page')
);
add_submenu_page(
'edit.php?post_type=wpdd_product',
__('Reports', 'wp-digital-download'),
__('Reports', 'wp-digital-download'),
'wpdd_view_reports',
'wpdd-reports',
array(__CLASS__, 'render_reports_page')
);
add_submenu_page(
'edit.php?post_type=wpdd_product',
__('Customers', 'wp-digital-download'),
__('Customers', 'wp-digital-download'),
'wpdd_manage_orders',
'wpdd-customers',
array(__CLASS__, 'render_customers_page')
);
add_submenu_page(
'edit.php?post_type=wpdd_product',
__('Shortcodes', 'wp-digital-download'),
__('Shortcodes', 'wp-digital-download'),
'edit_wpdd_products',
'wpdd-shortcodes',
array(__CLASS__, 'render_shortcodes_page')
);
}
if ($is_creator || $is_admin) {
// Creator-specific menus
add_submenu_page(
'edit.php?post_type=wpdd_product',
__('My Sales', 'wp-digital-download'),
__('My Sales', 'wp-digital-download'),
'wpdd_view_own_sales',
'wpdd-creator-sales',
array(__CLASS__, 'render_creator_sales_page')
);
add_submenu_page(
'edit.php?post_type=wpdd_product',
__('My Payouts', 'wp-digital-download'),
__('My Payouts', 'wp-digital-download'),
'wpdd_view_own_sales',
'wpdd-creator-payouts',
array(__CLASS__, 'render_creator_payouts_page')
);
}
}
public static function add_product_columns($columns) {
$new_columns = array();
foreach ($columns as $key => $value) {
$new_columns[$key] = $value;
if ($key === 'title') {
$new_columns['wpdd_price'] = __('Price', 'wp-digital-download');
$new_columns['wpdd_sales'] = __('Sales', 'wp-digital-download');
$new_columns['wpdd_revenue'] = __('Revenue', 'wp-digital-download');
$new_columns['wpdd_files'] = __('Files', 'wp-digital-download');
}
}
return $new_columns;
}
public static function render_product_columns($column, $post_id) {
switch ($column) {
case 'wpdd_price':
$price = get_post_meta($post_id, '_wpdd_price', true);
$sale_price = get_post_meta($post_id, '_wpdd_sale_price', true);
$is_free = get_post_meta($post_id, '_wpdd_is_free', true);
if ($is_free) {
echo '' . __('Free', 'wp-digital-download') . '';
} elseif ($sale_price && $sale_price < $price) {
echo '$' . number_format($price, 2) . ' ';
echo '$' . number_format($sale_price, 2) . '';
} else {
echo '$' . number_format($price, 2);
}
break;
case 'wpdd_sales':
global $wpdb;
$sales = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->prefix}wpdd_orders
WHERE product_id = %d AND status = 'completed'",
$post_id
));
echo intval($sales);
break;
case 'wpdd_revenue':
global $wpdb;
$revenue = $wpdb->get_var($wpdb->prepare(
"SELECT SUM(amount) FROM {$wpdb->prefix}wpdd_orders
WHERE product_id = %d AND status = 'completed'",
$post_id
));
echo '$' . number_format($revenue ?: 0, 2);
break;
case 'wpdd_files':
$files = get_post_meta($post_id, '_wpdd_files', true);
$count = is_array($files) ? count($files) : 0;
echo $count;
break;
}
}
public static function make_columns_sortable($columns) {
$columns['wpdd_price'] = 'wpdd_price';
$columns['wpdd_sales'] = 'wpdd_sales';
$columns['wpdd_revenue'] = 'wpdd_revenue';
return $columns;
}
public static function sort_products_by_column($query) {
if (!is_admin() || !$query->is_main_query()) {
return;
}
if ($query->get('post_type') !== 'wpdd_product') {
return;
}
$orderby = $query->get('orderby');
switch ($orderby) {
case 'wpdd_price':
$query->set('meta_key', '_wpdd_price');
$query->set('orderby', 'meta_value_num');
break;
case 'wpdd_sales':
$query->set('meta_key', '_wpdd_sales_count');
$query->set('orderby', 'meta_value_num');
break;
}
}
public static function render_orders_page() {
global $wpdb;
$page = isset($_GET['paged']) ? max(1, intval($_GET['paged'])) : 1;
$per_page = 20;
$offset = ($page - 1) * $per_page;
$where = array('1=1');
if (isset($_GET['status']) && $_GET['status']) {
$where[] = $wpdb->prepare("o.status = %s", sanitize_text_field($_GET['status']));
}
if (isset($_GET['product_id']) && $_GET['product_id']) {
$where[] = $wpdb->prepare("o.product_id = %d", intval($_GET['product_id']));
}
if (isset($_GET['search']) && $_GET['search']) {
$search = '%' . $wpdb->esc_like($_GET['search']) . '%';
$where[] = $wpdb->prepare(
"(o.order_number LIKE %s OR o.customer_email LIKE %s OR o.customer_name LIKE %s)",
$search, $search, $search
);
}
$where_clause = implode(' AND ', $where);
$total = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}wpdd_orders o WHERE {$where_clause}");
$orders = $wpdb->get_results($wpdb->prepare(
"SELECT o.*, p.post_title as product_name
FROM {$wpdb->prefix}wpdd_orders o
LEFT JOIN {$wpdb->posts} p ON o.product_id = p.ID
WHERE {$where_clause}
ORDER BY o.purchase_date DESC
LIMIT %d OFFSET %d",
$per_page,
$offset
));
?>
#order_number); ?> | product_name); ?> |
customer_name); ?> customer_email); ?> |
$amount, 2); ?> | status); ?> | purchase_date)); ?> | |
$total_revenue ?: 0, 2); ?>
total_orders); ?>
unique_customers); ?>
products_sold); ?>
post_title); ?> | sales); ?> | $revenue, 2); ?> |
display_name); ?> | sales); ?> | $revenue, 2); ?> |
[wpdd_shop]
[wpdd_shop posts_per_page="6" columns="2"]
[wpdd_shop category="music,videos" show_filters="no"]
[wpdd_shop orderby="price" order="ASC" columns="4"]
[wpdd_checkout]
[wpdd_customer_purchases]
[wpdd_thank_you]
[wpdd_single_product id="123"]
[wpdd_single_product id="456"]
[wpdd_buy_button id="123"]
[wpdd_buy_button id="789" text="Purchase Now"]
[wpdd_buy_button text="Get This Product" class="my-custom-button"]
[wpdd_shop] |
✓ ' . __('Created', 'wp-digital-download') . ''; echo ' (' . __('Edit', 'wp-digital-download') . ')'; } else { echo '✗ ' . __('Missing', 'wp-digital-download') . ''; } ?> | ||
[wpdd_checkout] |
✓ ' . __('Created', 'wp-digital-download') . ''; echo ' (' . __('Edit', 'wp-digital-download') . ')'; } else { echo '✗ ' . __('Missing', 'wp-digital-download') . ''; } ?> | ||
[wpdd_customer_purchases] |
✓ ' . __('Created', 'wp-digital-download') . ''; echo ' (' . __('Edit', 'wp-digital-download') . ')'; } else { echo '✗ ' . __('Missing', 'wp-digital-download') . ''; } ?> | ||
[wpdd_thank_you] |
✓ ' . __('Created', 'wp-digital-download') . ''; echo ' (' . __('Edit', 'wp-digital-download') . ')'; } else { echo '✗ ' . __('Missing', 'wp-digital-download') . ''; } ?> |
purchase_date))); ?> | product_name); ?> | customer_name); ?> | total, $currency); ?> | platform_fee, $currency); ?> | creator_earning, $currency); ?> | status)); ?> |
created_at))); ?> | amount, $payout->currency); ?> | paypal_email); ?> | '#fef3c7; color: #92400e;', 'completed' => '#d1fae5; color: #065f46;', 'failed' => '#fee2e2; color: #991b1b;', 'requested' => '#dbeafe; color: #1e40af;' ); $status_color = isset($status_colors[$payout->status]) ? $status_colors[$payout->status] : '#f3f4f6; color: #374151;'; ?> status)); ?> | transaction_id ?: '-'); ?> | processed_at ? esc_html(date_i18n(get_option('date_format'), strtotime($payout->processed_at))) : '-'; ?> |