First Commit

This commit is contained in:
2025-08-28 19:35:28 -07:00
commit 264e65006a
488 changed files with 155661 additions and 0 deletions

920
admin/class-wpdd-admin.php Normal file
View File

@@ -0,0 +1,920 @@
<?php
if (!defined('ABSPATH')) {
exit;
}
class WPDD_Admin {
public static function init() {
add_action('admin_menu', array(__CLASS__, 'add_admin_menus'));
add_filter('manage_wpdd_product_posts_columns', array(__CLASS__, 'add_product_columns'));
add_action('manage_wpdd_product_posts_custom_column', array(__CLASS__, 'render_product_columns'), 10, 2);
add_filter('manage_edit-wpdd_product_sortable_columns', array(__CLASS__, 'make_columns_sortable'));
add_action('pre_get_posts', array(__CLASS__, 'sort_products_by_column'));
add_action('admin_init', array(__CLASS__, 'handle_admin_actions'));
// Initialize admin payouts
if (class_exists('WPDD_Admin_Payouts')) {
WPDD_Admin_Payouts::init();
}
}
public static function add_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')
);
}
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 '<span style="color: green;">' . __('Free', 'wp-digital-download') . '</span>';
} elseif ($sale_price && $sale_price < $price) {
echo '<del>$' . number_format($price, 2) . '</del> ';
echo '<strong>$' . number_format($sale_price, 2) . '</strong>';
} 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
));
?>
<div class="wrap">
<h1><?php _e('Orders', 'wp-digital-download'); ?></h1>
<form method="get">
<input type="hidden" name="post_type" value="wpdd_product" />
<input type="hidden" name="page" value="wpdd-orders" />
<div class="tablenav top">
<div class="alignleft actions">
<select name="status">
<option value=""><?php _e('All Statuses', 'wp-digital-download'); ?></option>
<option value="pending" <?php selected(isset($_GET['status']) && $_GET['status'] == 'pending'); ?>>
<?php _e('Pending', 'wp-digital-download'); ?>
</option>
<option value="completed" <?php selected(isset($_GET['status']) && $_GET['status'] == 'completed'); ?>>
<?php _e('Completed', 'wp-digital-download'); ?>
</option>
<option value="failed" <?php selected(isset($_GET['status']) && $_GET['status'] == 'failed'); ?>>
<?php _e('Failed', 'wp-digital-download'); ?>
</option>
</select>
<input type="text" name="search" placeholder="<?php _e('Search orders...', 'wp-digital-download'); ?>"
value="<?php echo isset($_GET['search']) ? esc_attr($_GET['search']) : ''; ?>" />
<input type="submit" class="button" value="<?php _e('Filter', 'wp-digital-download'); ?>" />
</div>
</div>
</form>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php _e('Order', 'wp-digital-download'); ?></th>
<th><?php _e('Product', 'wp-digital-download'); ?></th>
<th><?php _e('Customer', 'wp-digital-download'); ?></th>
<th><?php _e('Amount', 'wp-digital-download'); ?></th>
<th><?php _e('Status', 'wp-digital-download'); ?></th>
<th><?php _e('Date', 'wp-digital-download'); ?></th>
<th><?php _e('Actions', 'wp-digital-download'); ?></th>
</tr>
</thead>
<tbody>
<?php if ($orders) : ?>
<?php foreach ($orders as $order) : ?>
<tr>
<td><strong>#<?php echo esc_html($order->order_number); ?></strong></td>
<td>
<a href="<?php echo get_edit_post_link($order->product_id); ?>">
<?php echo esc_html($order->product_name); ?>
</a>
</td>
<td>
<?php echo esc_html($order->customer_name); ?><br>
<small><?php echo esc_html($order->customer_email); ?></small>
</td>
<td>$<?php echo number_format($order->amount, 2); ?></td>
<td>
<span class="wpdd-status wpdd-status-<?php echo esc_attr($order->status); ?>">
<?php echo ucfirst($order->status); ?>
</span>
</td>
<td><?php echo date_i18n(get_option('date_format'), strtotime($order->purchase_date)); ?></td>
<td>
<a href="<?php echo wp_nonce_url(
add_query_arg(array(
'action' => 'wpdd_view_order',
'order_id' => $order->id
)),
'wpdd_view_order_' . $order->id
); ?>" class="button button-small">
<?php _e('View', 'wp-digital-download'); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="7"><?php _e('No orders found.', 'wp-digital-download'); ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
<?php
$total_pages = ceil($total / $per_page);
if ($total_pages > 1) {
echo '<div class="tablenav bottom"><div class="tablenav-pages">';
echo paginate_links(array(
'base' => add_query_arg('paged', '%#%'),
'format' => '',
'current' => $page,
'total' => $total_pages
));
echo '</div></div>';
}
?>
</div>
<style>
.wpdd-status {
padding: 3px 8px;
border-radius: 3px;
font-size: 12px;
font-weight: 600;
}
.wpdd-status-completed { background: #d4edda; color: #155724; }
.wpdd-status-pending { background: #fff3cd; color: #856404; }
.wpdd-status-failed { background: #f8d7da; color: #721c24; }
</style>
<?php
}
public static function render_reports_page() {
global $wpdb;
$date_range = isset($_GET['range']) ? sanitize_text_field($_GET['range']) : '30days';
switch ($date_range) {
case '7days':
$start_date = date('Y-m-d', strtotime('-7 days'));
break;
case '30days':
$start_date = date('Y-m-d', strtotime('-30 days'));
break;
case '3months':
$start_date = date('Y-m-d', strtotime('-3 months'));
break;
case 'year':
$start_date = date('Y-m-d', strtotime('-1 year'));
break;
default:
$start_date = date('Y-m-d', strtotime('-30 days'));
}
$stats = $wpdb->get_row($wpdb->prepare(
"SELECT
COUNT(*) as total_orders,
SUM(amount) as total_revenue,
COUNT(DISTINCT customer_id) as unique_customers,
COUNT(DISTINCT product_id) as products_sold
FROM {$wpdb->prefix}wpdd_orders
WHERE status = 'completed'
AND purchase_date >= %s",
$start_date
));
$top_products = $wpdb->get_results($wpdb->prepare(
"SELECT
p.ID,
p.post_title,
COUNT(o.id) as sales,
SUM(o.amount) as revenue
FROM {$wpdb->prefix}wpdd_orders o
INNER JOIN {$wpdb->posts} p ON o.product_id = p.ID
WHERE o.status = 'completed'
AND o.purchase_date >= %s
GROUP BY p.ID
ORDER BY revenue DESC
LIMIT 10",
$start_date
));
$top_creators = $wpdb->get_results($wpdb->prepare(
"SELECT
u.ID,
u.display_name,
COUNT(o.id) as sales,
SUM(o.amount) as revenue
FROM {$wpdb->prefix}wpdd_orders o
INNER JOIN {$wpdb->users} u ON o.creator_id = u.ID
WHERE o.status = 'completed'
AND o.purchase_date >= %s
GROUP BY u.ID
ORDER BY revenue DESC
LIMIT 10",
$start_date
));
?>
<div class="wrap">
<h1><?php _e('Reports', 'wp-digital-download'); ?></h1>
<div class="wpdd-date-filter">
<form method="get">
<input type="hidden" name="post_type" value="wpdd_product" />
<input type="hidden" name="page" value="wpdd-reports" />
<select name="range" onchange="this.form.submit()">
<option value="7days" <?php selected($date_range, '7days'); ?>>
<?php _e('Last 7 Days', 'wp-digital-download'); ?>
</option>
<option value="30days" <?php selected($date_range, '30days'); ?>>
<?php _e('Last 30 Days', 'wp-digital-download'); ?>
</option>
<option value="3months" <?php selected($date_range, '3months'); ?>>
<?php _e('Last 3 Months', 'wp-digital-download'); ?>
</option>
<option value="year" <?php selected($date_range, 'year'); ?>>
<?php _e('Last Year', 'wp-digital-download'); ?>
</option>
</select>
</form>
</div>
<div class="wpdd-stats-grid">
<div class="wpdd-stat-box">
<h3><?php _e('Total Revenue', 'wp-digital-download'); ?></h3>
<p class="wpdd-stat-value">$<?php echo number_format($stats->total_revenue ?: 0, 2); ?></p>
</div>
<div class="wpdd-stat-box">
<h3><?php _e('Total Orders', 'wp-digital-download'); ?></h3>
<p class="wpdd-stat-value"><?php echo intval($stats->total_orders); ?></p>
</div>
<div class="wpdd-stat-box">
<h3><?php _e('Unique Customers', 'wp-digital-download'); ?></h3>
<p class="wpdd-stat-value"><?php echo intval($stats->unique_customers); ?></p>
</div>
<div class="wpdd-stat-box">
<h3><?php _e('Products Sold', 'wp-digital-download'); ?></h3>
<p class="wpdd-stat-value"><?php echo intval($stats->products_sold); ?></p>
</div>
</div>
<div class="wpdd-reports-tables">
<div class="wpdd-report-section">
<h2><?php _e('Top Products', 'wp-digital-download'); ?></h2>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php _e('Product', 'wp-digital-download'); ?></th>
<th><?php _e('Sales', 'wp-digital-download'); ?></th>
<th><?php _e('Revenue', 'wp-digital-download'); ?></th>
</tr>
</thead>
<tbody>
<?php if ($top_products) : ?>
<?php foreach ($top_products as $product) : ?>
<tr>
<td>
<a href="<?php echo get_edit_post_link($product->ID); ?>">
<?php echo esc_html($product->post_title); ?>
</a>
</td>
<td><?php echo intval($product->sales); ?></td>
<td>$<?php echo number_format($product->revenue, 2); ?></td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="3"><?php _e('No data available.', 'wp-digital-download'); ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="wpdd-report-section">
<h2><?php _e('Top Creators', 'wp-digital-download'); ?></h2>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php _e('Creator', 'wp-digital-download'); ?></th>
<th><?php _e('Sales', 'wp-digital-download'); ?></th>
<th><?php _e('Revenue', 'wp-digital-download'); ?></th>
</tr>
</thead>
<tbody>
<?php if ($top_creators) : ?>
<?php foreach ($top_creators as $creator) : ?>
<tr>
<td>
<a href="<?php echo get_edit_user_link($creator->ID); ?>">
<?php echo esc_html($creator->display_name); ?>
</a>
</td>
<td><?php echo intval($creator->sales); ?></td>
<td>$<?php echo number_format($creator->revenue, 2); ?></td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="3"><?php _e('No data available.', 'wp-digital-download'); ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<style>
.wpdd-date-filter {
margin: 20px 0;
}
.wpdd-stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin: 30px 0;
}
.wpdd-stat-box {
background: white;
padding: 20px;
border: 1px solid #ccd0d4;
border-radius: 4px;
}
.wpdd-stat-box h3 {
margin: 0 0 10px 0;
color: #23282d;
}
.wpdd-stat-value {
font-size: 32px;
font-weight: 600;
color: #2271b1;
margin: 0;
}
.wpdd-reports-tables {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
margin-top: 30px;
}
.wpdd-report-section h2 {
margin-bottom: 15px;
}
@media (max-width: 1200px) {
.wpdd-reports-tables {
grid-template-columns: 1fr;
}
}
</style>
<?php
}
public static function render_customers_page() {
global $wpdb;
// Get all users who have made purchases, regardless of their role
$customers = $wpdb->get_results(
"SELECT
u.ID,
u.user_email,
u.display_name,
u.user_registered,
COUNT(o.id) as total_orders,
SUM(o.amount) as total_spent,
MAX(o.purchase_date) as last_order_date
FROM {$wpdb->users} u
INNER JOIN {$wpdb->prefix}wpdd_orders o ON u.ID = o.customer_id AND o.status = 'completed'
GROUP BY u.ID
ORDER BY total_spent DESC"
);
?>
<div class="wrap">
<h1><?php _e('Customers', 'wp-digital-download'); ?></h1>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php _e('Customer', 'wp-digital-download'); ?></th>
<th><?php _e('Email', 'wp-digital-download'); ?></th>
<th><?php _e('Orders', 'wp-digital-download'); ?></th>
<th><?php _e('Total Spent', 'wp-digital-download'); ?></th>
<th><?php _e('Registered', 'wp-digital-download'); ?></th>
<th><?php _e('Last Order', 'wp-digital-download'); ?></th>
<th><?php _e('Actions', 'wp-digital-download'); ?></th>
</tr>
</thead>
<tbody>
<?php if ($customers) : ?>
<?php foreach ($customers as $customer) : ?>
<tr>
<td>
<strong><?php echo esc_html($customer->display_name); ?></strong>
</td>
<td><?php echo esc_html($customer->user_email); ?></td>
<td><?php echo intval($customer->total_orders); ?></td>
<td>$<?php echo number_format($customer->total_spent ?: 0, 2); ?></td>
<td><?php echo date_i18n(get_option('date_format'), strtotime($customer->user_registered)); ?></td>
<td>
<?php
echo $customer->last_order_date
? date_i18n(get_option('date_format'), strtotime($customer->last_order_date))
: '-';
?>
</td>
<td>
<a href="<?php echo get_edit_user_link($customer->ID); ?>" class="button button-small">
<?php _e('Edit', 'wp-digital-download'); ?>
</a>
<a href="<?php echo add_query_arg(array(
'post_type' => 'wpdd_product',
'page' => 'wpdd-orders',
'customer_id' => $customer->ID
), admin_url('edit.php')); ?>" class="button button-small">
<?php _e('View Orders', 'wp-digital-download'); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="7"><?php _e('No customers found.', 'wp-digital-download'); ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<?php
}
public static function handle_admin_actions() {
if (isset($_GET['action']) && $_GET['action'] === 'wpdd_view_order') {
if (!isset($_GET['order_id']) || !wp_verify_nonce($_GET['_wpnonce'] ?? '', 'wpdd_view_order_' . $_GET['order_id'])) {
return;
}
self::view_order_details(intval($_GET['order_id']));
}
}
private static function view_order_details($order_id) {
global $wpdb;
$order = $wpdb->get_row($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 o.id = %d",
$order_id
));
if (!$order) {
wp_die(__('Order not found.', 'wp-digital-download'));
}
include WPDD_PLUGIN_PATH . 'admin/views/order-details.php';
exit;
}
public static function render_shortcodes_page() {
?>
<div class="wrap">
<h1><?php _e('Available Shortcodes', 'wp-digital-download'); ?></h1>
<div class="wpdd-shortcodes-intro">
<p><?php _e('Use these shortcodes to display digital download content on your pages and posts. Simply copy and paste the shortcode into any page or post editor.', 'wp-digital-download'); ?></p>
</div>
<div class="wpdd-shortcodes-grid">
<!-- Shop Shortcode -->
<div class="wpdd-shortcode-card">
<h3><?php _e('Shop Page', 'wp-digital-download'); ?></h3>
<div class="wpdd-shortcode-example">
<code>[wpdd_shop]</code>
</div>
<p><?php _e('Displays a grid of all available products with filtering and pagination.', 'wp-digital-download'); ?></p>
<h4><?php _e('Available Parameters:', 'wp-digital-download'); ?></h4>
<ul class="wpdd-params-list">
<li><strong>posts_per_page</strong> - Number of products per page (default: 12)</li>
<li><strong>columns</strong> - Grid columns (default: 3, options: 1-6)</li>
<li><strong>orderby</strong> - Sort order (date, title, price, menu_order)</li>
<li><strong>order</strong> - ASC or DESC (default: DESC)</li>
<li><strong>category</strong> - Show only specific categories (comma separated slugs)</li>
<li><strong>show_filters</strong> - Show search/filter form (yes/no, default: yes)</li>
</ul>
<h4><?php _e('Examples:', 'wp-digital-download'); ?></h4>
<div class="wpdd-shortcode-examples">
<code>[wpdd_shop posts_per_page="6" columns="2"]</code><br>
<code>[wpdd_shop category="music,videos" show_filters="no"]</code><br>
<code>[wpdd_shop orderby="price" order="ASC" columns="4"]</code>
</div>
</div>
<!-- Checkout Shortcode -->
<div class="wpdd-shortcode-card">
<h3><?php _e('Checkout Page', 'wp-digital-download'); ?></h3>
<div class="wpdd-shortcode-example">
<code>[wpdd_checkout]</code>
</div>
<p><?php _e('Displays the checkout form for purchasing products. Typically used on a dedicated checkout page.', 'wp-digital-download'); ?></p>
<p class="wpdd-note"><?php _e('Note: This shortcode automatically detects the product to purchase from the URL parameter.', 'wp-digital-download'); ?></p>
</div>
<!-- Customer Purchases Shortcode -->
<div class="wpdd-shortcode-card">
<h3><?php _e('Customer Purchases', 'wp-digital-download'); ?></h3>
<div class="wpdd-shortcode-example">
<code>[wpdd_customer_purchases]</code>
</div>
<p><?php _e('Shows a table of customer\'s purchase history with download links. Requires user to be logged in.', 'wp-digital-download'); ?></p>
<p class="wpdd-note"><?php _e('Note: This page also supports guest access via email links sent after purchase.', 'wp-digital-download'); ?></p>
</div>
<!-- Thank You Shortcode -->
<div class="wpdd-shortcode-card">
<h3><?php _e('Thank You Page', 'wp-digital-download'); ?></h3>
<div class="wpdd-shortcode-example">
<code>[wpdd_thank_you]</code>
</div>
<p><?php _e('Displays order confirmation and download links after successful purchase. Used on the thank you page.', 'wp-digital-download'); ?></p>
<p class="wpdd-note"><?php _e('Note: This shortcode requires an order_id parameter in the URL.', 'wp-digital-download'); ?></p>
</div>
<!-- Single Product Shortcode -->
<div class="wpdd-shortcode-card">
<h3><?php _e('Single Product', 'wp-digital-download'); ?></h3>
<div class="wpdd-shortcode-example">
<code>[wpdd_single_product id="123"]</code>
</div>
<p><?php _e('Display a single product card anywhere on your site.', 'wp-digital-download'); ?></p>
<h4><?php _e('Parameters:', 'wp-digital-download'); ?></h4>
<ul class="wpdd-params-list">
<li><strong>id</strong> - Product ID (required)</li>
</ul>
<h4><?php _e('Example:', 'wp-digital-download'); ?></h4>
<div class="wpdd-shortcode-examples">
<code>[wpdd_single_product id="456"]</code>
</div>
</div>
<!-- Buy Button Shortcode -->
<div class="wpdd-shortcode-card">
<h3><?php _e('Buy Button', 'wp-digital-download'); ?></h3>
<div class="wpdd-shortcode-example">
<code>[wpdd_buy_button id="123"]</code>
</div>
<p><?php _e('Display just a buy button for a specific product.', 'wp-digital-download'); ?></p>
<h4><?php _e('Parameters:', 'wp-digital-download'); ?></h4>
<ul class="wpdd-params-list">
<li><strong>id</strong> - Product ID (default: current post ID)</li>
<li><strong>text</strong> - Button text (default: "Buy Now")</li>
<li><strong>class</strong> - CSS class for styling</li>
</ul>
<h4><?php _e('Examples:', 'wp-digital-download'); ?></h4>
<div class="wpdd-shortcode-examples">
<code>[wpdd_buy_button id="789" text="Purchase Now"]</code><br>
<code>[wpdd_buy_button text="Get This Product" class="my-custom-button"]</code>
</div>
</div>
</div>
<!-- Page Setup Section -->
<div class="wpdd-page-setup">
<h2><?php _e('Required Pages Setup', 'wp-digital-download'); ?></h2>
<p><?php _e('For the plugin to work correctly, you need these pages with their respective shortcodes:', 'wp-digital-download'); ?></p>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php _e('Page Name', 'wp-digital-download'); ?></th>
<th><?php _e('Shortcode', 'wp-digital-download'); ?></th>
<th><?php _e('Purpose', 'wp-digital-download'); ?></th>
<th><?php _e('Status', 'wp-digital-download'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong><?php _e('Shop', 'wp-digital-download'); ?></strong></td>
<td><code>[wpdd_shop]</code></td>
<td><?php _e('Main product listing page', 'wp-digital-download'); ?></td>
<td>
<?php
$shop_page_id = get_option('wpdd_shop_page_id');
if ($shop_page_id && get_post($shop_page_id)) {
echo '<span style="color: green;">✓ ' . __('Created', 'wp-digital-download') . '</span>';
echo ' (<a href="' . get_edit_post_link($shop_page_id) . '">' . __('Edit', 'wp-digital-download') . '</a>)';
} else {
echo '<span style="color: red;">✗ ' . __('Missing', 'wp-digital-download') . '</span>';
}
?>
</td>
</tr>
<tr>
<td><strong><?php _e('Checkout', 'wp-digital-download'); ?></strong></td>
<td><code>[wpdd_checkout]</code></td>
<td><?php _e('Purchase processing page', 'wp-digital-download'); ?></td>
<td>
<?php
$checkout_page_id = get_option('wpdd_checkout_page_id');
if ($checkout_page_id && get_post($checkout_page_id)) {
echo '<span style="color: green;">✓ ' . __('Created', 'wp-digital-download') . '</span>';
echo ' (<a href="' . get_edit_post_link($checkout_page_id) . '">' . __('Edit', 'wp-digital-download') . '</a>)';
} else {
echo '<span style="color: red;">✗ ' . __('Missing', 'wp-digital-download') . '</span>';
}
?>
</td>
</tr>
<tr>
<td><strong><?php _e('My Purchases', 'wp-digital-download'); ?></strong></td>
<td><code>[wpdd_customer_purchases]</code></td>
<td><?php _e('Customer purchase history', 'wp-digital-download'); ?></td>
<td>
<?php
$purchases_page_id = get_option('wpdd_purchases_page_id');
if ($purchases_page_id && get_post($purchases_page_id)) {
echo '<span style="color: green;">✓ ' . __('Created', 'wp-digital-download') . '</span>';
echo ' (<a href="' . get_edit_post_link($purchases_page_id) . '">' . __('Edit', 'wp-digital-download') . '</a>)';
} else {
echo '<span style="color: red;">✗ ' . __('Missing', 'wp-digital-download') . '</span>';
}
?>
</td>
</tr>
<tr>
<td><strong><?php _e('Thank You', 'wp-digital-download'); ?></strong></td>
<td><code>[wpdd_thank_you]</code></td>
<td><?php _e('Post-purchase confirmation', 'wp-digital-download'); ?></td>
<td>
<?php
$thank_you_page_id = get_option('wpdd_thank_you_page_id');
if ($thank_you_page_id && get_post($thank_you_page_id)) {
echo '<span style="color: green;">✓ ' . __('Created', 'wp-digital-download') . '</span>';
echo ' (<a href="' . get_edit_post_link($thank_you_page_id) . '">' . __('Edit', 'wp-digital-download') . '</a>)';
} else {
echo '<span style="color: red;">✗ ' . __('Missing', 'wp-digital-download') . '</span>';
}
?>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<style>
.wpdd-shortcodes-intro {
background: #f1f1f1;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.wpdd-shortcodes-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
gap: 20px;
margin: 30px 0;
}
.wpdd-shortcode-card {
background: #fff;
border: 1px solid #ccd0d4;
border-radius: 5px;
padding: 20px;
}
.wpdd-shortcode-card h3 {
margin-top: 0;
color: #23282d;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.wpdd-shortcode-example {
background: #f8f9fa;
padding: 10px;
border-radius: 3px;
margin: 10px 0;
font-family: monospace;
border-left: 4px solid #2271b1;
}
.wpdd-shortcode-examples {
background: #f8f9fa;
padding: 10px;
border-radius: 3px;
margin: 10px 0;
}
.wpdd-shortcode-examples code {
display: block;
margin: 5px 0;
color: #d63384;
}
.wpdd-params-list {
background: #fafafa;
padding: 10px 30px;
border-radius: 3px;
margin: 10px 0;
}
.wpdd-params-list li {
margin: 8px 0;
}
.wpdd-note {
background: #fff3cd;
border: 1px solid #ffeaa7;
color: #856404;
padding: 10px;
border-radius: 3px;
font-style: italic;
}
.wpdd-page-setup {
margin-top: 40px;
padding-top: 30px;
border-top: 2px solid #ddd;
}
.wpdd-page-setup h2 {
color: #23282d;
margin-bottom: 15px;
}
</style>
<?php
}
}