Coupon rework, reports, and styles. Closes #1862.
This commit is contained in:
parent
084a247a20
commit
a697ffbeb6
|
@ -22,7 +22,7 @@ function woocommerce_edit_coupon_columns($columns){
|
|||
$columns = array();
|
||||
|
||||
$columns["cb"] = "<input type=\"checkbox\" />";
|
||||
$columns["title"] = __( 'Code', 'woocommerce' );
|
||||
$columns["coupon_code"] = __( 'Code', 'woocommerce' );
|
||||
$columns["type"] = __( 'Coupon type', 'woocommerce' );
|
||||
$columns["amount"] = __( 'Coupon amount', 'woocommerce' );
|
||||
$columns["description"] = __( 'Description', 'woocommerce' );
|
||||
|
@ -47,6 +47,43 @@ function woocommerce_custom_coupon_columns( $column ) {
|
|||
global $post, $woocommerce;
|
||||
|
||||
switch ( $column ) {
|
||||
case "coupon_code" :
|
||||
$edit_link = get_edit_post_link( $post->ID );
|
||||
$title = _draft_or_post_title();
|
||||
$post_type_object = get_post_type_object( $post->post_type );
|
||||
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
|
||||
|
||||
echo '<div class="code tips" data-tip="' . __( 'Edit coupon', 'woocommerce' ) . '"><a href="' . esc_attr( $edit_link ) . '"><span>' . esc_html( $title ). '</span></a></div>';
|
||||
|
||||
_post_states( $post );
|
||||
|
||||
// Get actions
|
||||
$actions = array();
|
||||
|
||||
if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
|
||||
if ( 'trash' == $post->post_status )
|
||||
$actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore', 'woocommerce' ) . "</a>";
|
||||
elseif ( EMPTY_TRASH_DAYS )
|
||||
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash', 'woocommerce' ) . "</a>";
|
||||
if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
|
||||
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently', 'woocommerce' ) . "</a>";
|
||||
}
|
||||
|
||||
$actions = apply_filters( 'post_row_actions', $actions, $post );
|
||||
|
||||
echo '<div class="row-actions">';
|
||||
|
||||
$i = 0;
|
||||
$action_count = sizeof($actions);
|
||||
|
||||
foreach ( $actions as $action => $link ) {
|
||||
++$i;
|
||||
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
|
||||
echo "<span class='$action'>$link$sep</span>";
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
break;
|
||||
case "type" :
|
||||
echo esc_html( $woocommerce->get_coupon_discount_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
|
||||
break;
|
||||
|
|
|
@ -478,7 +478,7 @@ function woocommerce_order_actions_meta_box($post) {
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_order_totals_meta_box( $post ) {
|
||||
global $woocommerce, $theorder;
|
||||
global $woocommerce, $theorder, $wpdb;
|
||||
|
||||
if ( ! is_object( $theorder ) )
|
||||
$theorder = new WC_Order( $post->ID );
|
||||
|
@ -508,7 +508,25 @@ function woocommerce_order_totals_meta_box( $post ) {
|
|||
</li>
|
||||
|
||||
</ul>
|
||||
<div class="clear"></div>
|
||||
|
||||
<ul class="wc_coupon_list">
|
||||
|
||||
<?php
|
||||
$coupons = $order->get_items( array( 'coupon' ) );
|
||||
|
||||
foreach ( $coupons as $item_id => $item ) {
|
||||
|
||||
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item['name'] ) );
|
||||
|
||||
$link = $post_id ? admin_url( 'post.php?post=' . $post_id . '&action=edit' ) : admin_url( 'edit.php?s=' . esc_url( $item['name'] ) . '&post_status=all&post_type=shop_coupon' );
|
||||
|
||||
echo '<li class="tips code" data-tip="' . esc_attr( woocommerce_price( $item['discount_amount'] ) ) . '"><a href="' . $link . '"><span>' . esc_html( $item['name'] ). '</span></a></li>';
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
<div class="totals_group">
|
||||
<h4><?php _e( 'Shipping', 'woocommerce' ); ?></h4>
|
||||
|
|
|
@ -66,11 +66,21 @@ function woocommerce_reports() {
|
|||
'title' => __( 'Sales by category', 'woocommerce' ),
|
||||
'description' => '',
|
||||
'function' => 'woocommerce_category_sales'
|
||||
) )
|
||||
),
|
||||
'coupons' => array(
|
||||
'title' => __( 'Coupons', 'woocommerce' ),
|
||||
'charts' => array(
|
||||
array(
|
||||
'title' => __( 'Overview', 'woocommerce' ),
|
||||
'description' => '',
|
||||
'hide_title' => true,
|
||||
'function' => 'woocommerce_coupons_overview'
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Sales by coupon', 'woocommerce' ),
|
||||
'title' => __( 'Discounts by coupon', 'woocommerce' ),
|
||||
'description' => '',
|
||||
'function' => 'woocommerce_coupon_sales'
|
||||
'function' => 'woocommerce_coupon_discounts'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
@ -1234,6 +1244,475 @@ function woocommerce_product_sales() {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output the coupons overview stats.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_coupons_overview() {
|
||||
global $start_date, $end_date, $woocommerce, $wpdb;
|
||||
|
||||
$start_date = isset( $_POST['start_date'] ) ? $_POST['start_date'] : '';
|
||||
$end_date = isset( $_POST['end_date'] ) ? $_POST['end_date'] : '';
|
||||
|
||||
if ( ! $start_date )
|
||||
$start_date = date( 'Ymd', strtotime( date('Ym', current_time( 'timestamp' ) ) . '01' ) );
|
||||
if ( ! $end_date )
|
||||
$end_date = date( 'Ymd', current_time( 'timestamp' ) );
|
||||
|
||||
$start_date = strtotime( $start_date );
|
||||
$end_date = strtotime( $end_date );
|
||||
|
||||
$total_order_count = apply_filters( 'woocommerce_reports_coupons_overview_total_order_count', absint( $wpdb->get_var( "
|
||||
SELECT COUNT( DISTINCT posts.ID ) as order_count
|
||||
FROM {$wpdb->posts} AS posts
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
WHERE term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND post_date > '" . date('Y-m-d', $start_date ) . "'
|
||||
AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "'
|
||||
" ) ) );
|
||||
|
||||
$coupon_totals = apply_filters( 'woocommerce_reports_coupons_overview_totals', $wpdb->get_row( "
|
||||
SELECT COUNT( DISTINCT posts.ID ) as order_count, SUM( order_item_meta.meta_value ) as total_discount
|
||||
FROM {$wpdb->prefix}woocommerce_order_items as order_items
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
WHERE term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND order_items.order_item_type = 'coupon'
|
||||
AND order_item_meta.meta_key = 'discount_amount'
|
||||
AND post_date > '" . date('Y-m-d', $start_date ) . "'
|
||||
AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "'
|
||||
" ) );
|
||||
|
||||
$coupons_by_count = apply_filters( 'woocommerce_reports_coupons_overview_coupons_by_count', $wpdb->get_results( "
|
||||
SELECT COUNT( order_items.order_id ) as count, order_items.*
|
||||
FROM {$wpdb->prefix}woocommerce_order_items as order_items
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
WHERE term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND order_items.order_item_type = 'coupon'
|
||||
AND order_item_meta.meta_key = 'discount_amount'
|
||||
AND order_items.order_item_name != ''
|
||||
AND post_date > '" . date('Y-m-d', $start_date ) . "'
|
||||
AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "'
|
||||
GROUP BY order_items.order_item_name
|
||||
ORDER BY count DESC
|
||||
LIMIT 15
|
||||
" ) );
|
||||
|
||||
$coupons_by_amount = apply_filters( 'woocommerce_reports_coupons_overview_coupons_by_count', $wpdb->get_results( "
|
||||
SELECT SUM( order_item_meta.meta_value ) as amount, order_items.*
|
||||
FROM {$wpdb->prefix}woocommerce_order_items as order_items
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
WHERE term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND order_items.order_item_type = 'coupon'
|
||||
AND order_item_meta.meta_key = 'discount_amount'
|
||||
AND order_items.order_item_name != ''
|
||||
AND post_date > '" . date('Y-m-d', $start_date ) . "'
|
||||
AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "'
|
||||
GROUP BY order_items.order_item_name
|
||||
ORDER BY amount DESC
|
||||
LIMIT 15
|
||||
" ) );
|
||||
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<p><label for="from"><?php _e( 'From:', 'woocommerce' ); ?></label> <input type="text" name="start_date" id="from" readonly="readonly" value="<?php echo esc_attr( date('Y-m-d', $start_date) ); ?>" /> <label for="to"><?php _e( 'To:', 'woocommerce' ); ?></label> <input type="text" name="end_date" id="to" readonly="readonly" value="<?php echo esc_attr( date('Y-m-d', $end_date) ); ?>" /> <input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /></p>
|
||||
</form>
|
||||
|
||||
<div id="poststuff" class="woocommerce-reports-wrap">
|
||||
<div class="woocommerce-reports-sidebar">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Total orders containing coupons', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php if ( $coupon_totals->order_count > 0 ) echo absint( $coupon_totals->order_count ); else _e( 'n/a', 'woocommerce' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Percent of orders containing coupons', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php if ( $coupon_totals->order_count > 0 ) echo round( $coupon_totals->order_count / $total_order_count * 100, 2 ) . '%'; else _e( 'n/a', 'woocommerce' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Total coupon discount', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php if ( $coupon_totals->total_discount > 0 ) echo woocommerce_price( $coupon_totals->total_discount ); else _e( 'n/a', 'woocommerce' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="woocommerce-reports-main">
|
||||
<div class="woocommerce-reports-left">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Most popular coupons', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<ul class="wc_coupon_list wc_coupon_list_block">
|
||||
<?php
|
||||
if ( $coupons_by_count ) {
|
||||
foreach ( $coupons_by_count as $coupon ) {
|
||||
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $coupon->order_item_name ) );
|
||||
|
||||
$link = $post_id ? admin_url( 'post.php?post=' . $post_id . '&action=edit' ) : admin_url( 'edit.php?s=' . esc_url( $coupon->order_item_name ) . '&post_status=all&post_type=shop_coupon' );
|
||||
|
||||
echo '<li><a href="' . $link . '" class="code"><span><span>' . esc_html( $coupon->order_item_name ). '</span></span></a> - ' . sprintf( _n( 'Used 1 time', 'Used %d times', $coupon->count, 'woocommerce' ), absint( $coupon->count ) ) . '</li>';
|
||||
}
|
||||
} else {
|
||||
echo '<li>' . __( 'No coupons found', 'woocommerce' ) . '</li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="woocommerce-reports-right">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Greatest discount amount', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<ul class="wc_coupon_list wc_coupon_list_block">
|
||||
<?php
|
||||
if ( $coupons_by_amount ) {
|
||||
foreach ( $coupons_by_amount as $coupon ) {
|
||||
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $coupon->order_item_name ) );
|
||||
|
||||
$link = $post_id ? admin_url( 'post.php?post=' . $post_id . '&action=edit' ) : admin_url( 'edit.php?s=' . esc_url( $coupon->order_item_name ) . '&post_status=all&post_type=shop_coupon' );
|
||||
|
||||
echo '<li><a href="' . $link . '" class="code"><span><span>' . esc_html( $coupon->order_item_name ). '</span></span></a> - ' . sprintf( __( 'Discounted %s', 'woocommerce' ), woocommerce_price( $coupon->amount ) ) . '</li>';
|
||||
}
|
||||
} else {
|
||||
echo '<li>' . __( 'No coupons found', 'woocommerce' ) . '</li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
<?php woocommerce_datepicker_js(); ?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* woocommerce_coupon_discounts function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_coupon_discounts() {
|
||||
global $start_date, $end_date, $woocommerce, $wpdb, $wp_locale;
|
||||
|
||||
$first_year = $wpdb->get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 AND post_type='shop_order' ORDER BY post_date ASC LIMIT 1;" );
|
||||
$first_year = ( $first_year ) ? date( 'Y', strtotime( $first_year ) ) : date( 'Y' );
|
||||
|
||||
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
|
||||
$start_date = strtotime( $current_year . '0101' );
|
||||
|
||||
$order_statuses = implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) );
|
||||
|
||||
$used_coupons = apply_filters( 'woocommerce_reports_coupons_sales_used_coupons', $wpdb->get_col( "
|
||||
SELECT order_items.order_item_name
|
||||
FROM {$wpdb->prefix}woocommerce_order_items as order_items
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
WHERE term.slug IN ('{$order_statuses}')
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND order_items.order_item_type = 'coupon'
|
||||
AND order_item_meta.meta_key = 'discount_amount'
|
||||
AND order_items.order_item_name != ''
|
||||
GROUP BY order_items.order_item_name
|
||||
ORDER BY order_items.order_item_name ASC
|
||||
" ) );
|
||||
?>
|
||||
|
||||
<form method="post" action="" class="report_filters">
|
||||
<p>
|
||||
<label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label>
|
||||
<select name="show_year" id="show_year">
|
||||
<?php
|
||||
for ( $i = $first_year; $i <= date( 'Y' ); $i++ )
|
||||
printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i );
|
||||
?>
|
||||
</select>
|
||||
|
||||
<select multiple="multiple" class="chosen_select" id="show_coupons" name="show_coupons[]" style="width: 300px;">
|
||||
<?php
|
||||
foreach ( $used_coupons as $coupon )
|
||||
echo '<option value="' . $coupon . '" ' . selected( ! empty( $_POST['show_coupons'] ) && in_array( $coupon, $_POST['show_coupons'] ), true ) . '>' . $coupon . '</option>';
|
||||
?>
|
||||
</select>
|
||||
|
||||
<input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
if ( ! empty( $_POST['show_coupons'] ) && count( $_POST['show_coupons'] ) > 0 ) {
|
||||
|
||||
$coupons = $_POST['show_coupons'];
|
||||
|
||||
$coupon_sales = $monthly_totals = array();
|
||||
|
||||
foreach( $coupons as $coupon ) {
|
||||
|
||||
$coupon_amounts = apply_filters( 'woocommerce_reports_coupon_sales_order_totals', $wpdb->get_results( $wpdb->prepare( "
|
||||
SELECT order_items.order_item_name, date_format(posts.post_date, '%%Y%%m') as month, SUM( order_item_meta.meta_value ) as discount_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items as order_items
|
||||
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
WHERE term.slug IN ('{$order_statuses}')
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND order_items.order_item_type = 'coupon'
|
||||
AND order_item_meta.meta_key = 'discount_amount'
|
||||
AND '{$current_year}' = date_format(posts.post_date,'%%Y')
|
||||
AND order_items.order_item_name = %s
|
||||
GROUP BY month
|
||||
", $coupon ) ), $order_statuses, $current_year, $coupon );
|
||||
|
||||
foreach( $coupon_amounts as $sales ) {
|
||||
$month = $sales->month;
|
||||
$coupon_sales[ $coupon ][ $month ] = $sales->discount_total;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="woocommerce-wide-reports-wrap">
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Coupon', 'woocommerce' ); ?></th>
|
||||
<?php
|
||||
$column_count = 0;
|
||||
for ( $count = 0; $count < 12; $count++ ) :
|
||||
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
|
||||
continue;
|
||||
$month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) );
|
||||
|
||||
// set elements before += them below
|
||||
$monthly_totals[$month] = 0;
|
||||
|
||||
$column_count++;
|
||||
?>
|
||||
<th><?php echo date( 'F', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ); ?></th>
|
||||
<?php endfor; ?>
|
||||
<th><strong><?php _e( 'Total', 'woocommerce' ); ?></strong></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody><?php
|
||||
|
||||
// save data for chart while outputting
|
||||
$chart_data = $coupon_totals = array();
|
||||
|
||||
foreach( $coupon_sales as $coupon_code => $sales ) {
|
||||
|
||||
echo '<tr><th>' . esc_html( $coupon_code ) . '</th>';
|
||||
|
||||
for ( $count = 0; $count < 12; $count ++ ) {
|
||||
|
||||
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
|
||||
continue;
|
||||
|
||||
$month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) );
|
||||
|
||||
$amount = isset( $sales[$month] ) ? $sales[$month] : 0;
|
||||
echo '<td>' . woocommerce_price( $amount ) . '</td>';
|
||||
|
||||
$monthly_totals[$month] += $amount;
|
||||
|
||||
$chart_data[$coupon_code][] = array( strtotime( date( 'Ymd', strtotime( $month . '01' ) ) ) . '000', $amount );
|
||||
|
||||
}
|
||||
|
||||
echo '<td><strong>' . woocommerce_price( array_sum( $sales ) ) . '</strong></td>';
|
||||
|
||||
// total sales across all months
|
||||
$coupon_totals[$coupon_code] = array_sum( $sales );
|
||||
|
||||
echo '</tr>';
|
||||
|
||||
}
|
||||
|
||||
if ( $coupon_totals ) {
|
||||
|
||||
$top_coupon_name = current( array_keys( $coupon_totals, max( $coupon_totals ) ) );
|
||||
$top_coupon_sales = $coupon_totals[$top_coupon_name];
|
||||
|
||||
$worst_coupon_name = current( array_keys( $coupon_totals, min( $coupon_totals ) ) );
|
||||
$worst_coupon_sales = $coupon_totals[$worst_coupon_name];
|
||||
|
||||
$median_coupon_sales = array_values( $coupon_totals );
|
||||
sort($median_coupon_sales);
|
||||
|
||||
} else {
|
||||
$top_coupon_name = $top_coupon_sales = $worst_coupon_name = $worst_coupon_sales = $median_coupon_sales = '';
|
||||
}
|
||||
|
||||
echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>';
|
||||
|
||||
foreach( $monthly_totals as $month => $totals )
|
||||
echo '<td><strong>' . woocommerce_price( $totals ) . '</strong></td>';
|
||||
|
||||
echo '<td><strong>' . woocommerce_price( array_sum( $monthly_totals ) ) . '</strong></td></tr>';
|
||||
|
||||
?></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php if ( sizeof( $coupon_totals ) > 1 ) : ?>
|
||||
<div id="poststuff" class="woocommerce-reports-wrap">
|
||||
<div class="woocommerce-reports-sidebar">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Top coupon', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo $top_coupon_name . ' (' . woocommerce_price( $top_coupon_sales ) . ')';
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Worst coupon', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo $worst_coupon_name . ' (' . woocommerce_price( $worst_coupon_sales ) . ')';
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Discount average', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo woocommerce_price( array_sum( $coupon_totals ) / count( $coupon_totals ) );
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Discount median', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
if ( count( $median_coupon_sales ) == 2 )
|
||||
echo __( 'N/A', 'woocommerce' );
|
||||
elseif ( count( $median_coupon_sales ) % 2 )
|
||||
echo woocommerce_price(
|
||||
(
|
||||
$median_coupon_sales[ floor( count( $median_coupon_sales ) / 2 ) ] + $median_coupon_sales[ ceil( count( $median_coupon_sales ) / 2 ) ]
|
||||
) / 2
|
||||
);
|
||||
else
|
||||
|
||||
echo woocommerce_price( $median_coupon_sales[ count( $median_coupon_sales ) / 2 ] );
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="woocommerce-reports-main">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Monthly discounts by coupon', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside chart">
|
||||
<div id="placeholder" style="width:100%; overflow:hidden; height:568px; position:relative;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
|
||||
<?php
|
||||
// Variables
|
||||
foreach ( $chart_data as $name => $data ) {
|
||||
$varname = 'coupon_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data';
|
||||
echo 'var ' . $varname . ' = jQuery.parseJSON( \'' . json_encode( $data ) . '\' );';
|
||||
}
|
||||
?>
|
||||
|
||||
var placeholder = jQuery("#placeholder");
|
||||
|
||||
var plot = jQuery.plot(placeholder, [
|
||||
<?php
|
||||
$labels = array();
|
||||
|
||||
foreach ( $chart_data as $name => $data ) {
|
||||
$labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'coupon_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }';
|
||||
}
|
||||
|
||||
echo implode( ',', $labels );
|
||||
?>
|
||||
], {
|
||||
series: {
|
||||
lines: { show: true, fill: true },
|
||||
points: { show: true, align: "left" }
|
||||
},
|
||||
grid: {
|
||||
show: true,
|
||||
aboveData: false,
|
||||
color: '#aaa',
|
||||
backgroundColor: '#fff',
|
||||
borderWidth: 2,
|
||||
borderColor: '#aaa',
|
||||
clickable: false,
|
||||
hoverable: true
|
||||
},
|
||||
xaxis: {
|
||||
mode: "time",
|
||||
timeformat: "%b %y",
|
||||
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
|
||||
tickLength: 1,
|
||||
minTickSize: [1, "month"]
|
||||
},
|
||||
yaxes: [ { min: 0, tickDecimals: 2 } ]
|
||||
});
|
||||
|
||||
placeholder.resize();
|
||||
|
||||
<?php woocommerce_tooltip_js(); ?>
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
} // end POST check
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
jQuery("select.chosen_select").chosen();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output the customer overview stats.
|
||||
*
|
||||
|
@ -2220,296 +2699,4 @@ function woocommerce_category_sales() {
|
|||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* woocommerce_coupon_sales function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_coupon_sales() {
|
||||
global $start_date, $end_date, $woocommerce, $wpdb, $wp_locale;
|
||||
|
||||
$first_year = $wpdb->get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 AND post_type='shop_order' ORDER BY post_date ASC LIMIT 1;" );
|
||||
$first_year = ( $first_year ) ? date( 'Y', strtotime( $first_year ) ) : date( 'Y' );
|
||||
|
||||
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
|
||||
$start_date = strtotime( $current_year . '0101' );
|
||||
|
||||
$order_statuses = implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) );
|
||||
|
||||
$coupons = $wpdb->get_col( "
|
||||
SELECT DISTINCT meta.meta_value FROM {$wpdb->postmeta} AS meta
|
||||
LEFT JOIN {$wpdb->posts} AS posts ON posts.ID = meta.post_id
|
||||
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
||||
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
|
||||
WHERE meta.meta_key = 'coupons'
|
||||
AND posts.post_type = 'shop_order'
|
||||
AND posts.post_status = 'publish'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND term.slug IN ('{$order_statuses}')
|
||||
" );
|
||||
?>
|
||||
|
||||
<form method="post" action="" class="report_filters">
|
||||
<p>
|
||||
<label for="show_year"><?php _e( 'Show:', 'woocommerce' ); ?></label>
|
||||
<select name="show_year" id="show_year">
|
||||
<?php
|
||||
for ( $i = $first_year; $i <= date( 'Y' ); $i++ )
|
||||
printf( '<option value="%s" %s>%s</option>', $i, selected( $current_year, $i, false ), $i );
|
||||
?>
|
||||
</select>
|
||||
|
||||
<select multiple="multiple" class="chosen_select" id="show_coupons" name="show_coupons[]" style="width: 300px;">
|
||||
<?php
|
||||
foreach ( $coupons as $coupon ) {
|
||||
|
||||
echo '<option value="' . $coupon . '" ' . selected( ! empty( $_POST['show_coupons'] ) && in_array( $coupon, $_POST['show_coupons'] ), true ) . '>' . $coupon . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
<input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
if ( ! empty( $_POST['show_coupons'] ) && count( $_POST['show_coupons'] ) > 0 ) :
|
||||
|
||||
$coupons = $_POST['show_coupons'];
|
||||
|
||||
$coupon_sales = $monthly_totals = array();
|
||||
|
||||
foreach( $coupons as $coupon ) :
|
||||
|
||||
$monthly_sales = apply_filters( 'woocommerce_reports_coupon_sales_order_totals', $wpdb->get_results( $wpdb->prepare( "
|
||||
SELECT SUM(postmeta.meta_value) AS order_total, date_format(posts.post_date, '%%Y%%m') as month FROM {$wpdb->posts} AS posts
|
||||
|
||||
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID=postmeta.post_ID
|
||||
INNER JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
||||
INNER JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
||||
INNER JOIN {$wpdb->terms} AS term USING( term_id )
|
||||
|
||||
WHERE postmeta.meta_key = '_order_total'
|
||||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND term.slug IN ('{$order_statuses}')
|
||||
AND posts.post_type = 'shop_order'
|
||||
AND posts.post_status = 'publish'
|
||||
AND '{$current_year}' = date_format(posts.post_date,'%%Y')
|
||||
AND posts.ID IN (
|
||||
SELECT post_id FROM {$wpdb->postmeta} AS meta
|
||||
|
||||
WHERE meta.meta_key = 'coupons'
|
||||
AND meta.meta_value = '%s'
|
||||
)
|
||||
GROUP BY month", $coupon ), OBJECT ), $order_statuses, $current_year, $coupon);
|
||||
|
||||
foreach( $monthly_sales as $sales ) {
|
||||
$month = $sales->month;
|
||||
$coupon_sales[$coupon][$month] = $sales->order_total;
|
||||
}
|
||||
|
||||
|
||||
endforeach;
|
||||
?>
|
||||
<div class="woocommerce-wide-reports-wrap">
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Coupon', 'woocommerce' ); ?></th>
|
||||
<?php
|
||||
$column_count = 0;
|
||||
for ( $count = 0; $count < 12; $count++ ) :
|
||||
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
|
||||
continue;
|
||||
$month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) );
|
||||
|
||||
// set elements before += them below
|
||||
$monthly_totals[$month] = 0;
|
||||
|
||||
$column_count++;
|
||||
?>
|
||||
<th><?php echo date( 'F', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ); ?></th>
|
||||
<?php endfor; ?>
|
||||
<th><strong><?php _e( 'Total', 'woocommerce' ); ?></strong></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody><?php
|
||||
|
||||
// save data for chart while outputting
|
||||
$chart_data = $coupon_totals = array();
|
||||
|
||||
foreach( $coupon_sales as $coupon_code => $sales ) {
|
||||
|
||||
echo '<tr><th>' . esc_html( $coupon_code ) . '</th>';
|
||||
|
||||
for ( $count = 0; $count < 12; $count ++ ) {
|
||||
|
||||
if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) )
|
||||
continue;
|
||||
|
||||
$month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) );
|
||||
|
||||
$amount = isset( $sales[$month] ) ? $sales[$month] : 0;
|
||||
echo '<td>' . woocommerce_price( $amount ) . '</td>';
|
||||
|
||||
$monthly_totals[$month] += $amount;
|
||||
|
||||
$chart_data[$coupon_code][] = array( strtotime( date( 'Ymd', strtotime( $month . '01' ) ) ) . '000', $amount );
|
||||
|
||||
}
|
||||
|
||||
echo '<td><strong>' . woocommerce_price( array_sum( $sales ) ) . '</strong></td>';
|
||||
|
||||
// total sales across all months
|
||||
$coupon_totals[$coupon_code] = array_sum( $sales );
|
||||
|
||||
echo '</tr>';
|
||||
|
||||
}
|
||||
|
||||
$top_coupon_name = current( array_keys( $coupon_totals, max( $coupon_totals ) ) );
|
||||
$top_coupon_sales = $coupon_totals[$top_coupon_name];
|
||||
|
||||
$worst_coupon_name = current( array_keys( $coupon_totals, min( $coupon_totals ) ) );
|
||||
$worst_coupon_sales = $coupon_totals[$worst_coupon_name];
|
||||
|
||||
$median_coupon_sales = array_values( $coupon_totals );
|
||||
sort($median_coupon_sales);
|
||||
|
||||
echo '<tr><th><strong>' . __( 'Total', 'woocommerce' ) . '</strong></th>';
|
||||
|
||||
foreach( $monthly_totals as $month => $totals )
|
||||
echo '<td><strong>' . woocommerce_price( $totals ) . '</strong></td>';
|
||||
|
||||
echo '<td><strong>' . woocommerce_price( array_sum( $monthly_totals ) ) . '</strong></td></tr>';
|
||||
|
||||
?></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="poststuff" class="woocommerce-reports-wrap">
|
||||
<div class="woocommerce-reports-sidebar">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Top coupon', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo $top_coupon_name . ' (' . woocommerce_price( $top_coupon_sales ) . ')';
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ( sizeof( $coupon_totals ) > 1 ) : ?>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Worst coupon', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo $worst_coupon_name . ' (' . woocommerce_price( $worst_coupon_sales ) . ')';
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Coupon sales average', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
echo woocommerce_price( array_sum( $coupon_totals ) / count( $coupon_totals ) );
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Coupon sales median', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside">
|
||||
<p class="stat"><?php
|
||||
if ( count( $median_coupon_sales ) == 2 )
|
||||
echo __( 'N/A', 'woocommerce' );
|
||||
elseif ( count( $median_coupon_sales ) % 2 )
|
||||
echo woocommerce_price(
|
||||
(
|
||||
$median_coupon_sales[ floor( count( $median_coupon_sales ) / 2 ) ] + $median_coupon_sales[ ceil( count( $median_coupon_sales ) / 2 ) ]
|
||||
) / 2
|
||||
);
|
||||
else
|
||||
|
||||
echo woocommerce_price( $median_coupon_sales[ count( $median_coupon_sales ) / 2 ] );
|
||||
?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="woocommerce-reports-main">
|
||||
<div class="postbox">
|
||||
<h3><span><?php _e( 'Monthly sales by coupon', 'woocommerce' ); ?></span></h3>
|
||||
<div class="inside chart">
|
||||
<div id="placeholder" style="width:100%; overflow:hidden; height:568px; position:relative;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
|
||||
<?php
|
||||
// Variables
|
||||
foreach ( $chart_data as $name => $data ) {
|
||||
$varname = 'coupon_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data';
|
||||
echo 'var ' . $varname . ' = jQuery.parseJSON( \'' . json_encode( $data ) . '\' );';
|
||||
}
|
||||
?>
|
||||
|
||||
var placeholder = jQuery("#placeholder");
|
||||
|
||||
var plot = jQuery.plot(placeholder, [
|
||||
<?php
|
||||
$labels = array();
|
||||
|
||||
foreach ( $chart_data as $name => $data ) {
|
||||
$labels[] = '{ label: "' . esc_js( $name ) . '", data: ' . 'coupon_' . str_replace( '-', '_', sanitize_title( $name ) ) . '_data }';
|
||||
}
|
||||
|
||||
echo implode( ',', $labels );
|
||||
?>
|
||||
], {
|
||||
series: {
|
||||
lines: { show: true, fill: true },
|
||||
points: { show: true, align: "left" }
|
||||
},
|
||||
grid: {
|
||||
show: true,
|
||||
aboveData: false,
|
||||
color: '#aaa',
|
||||
backgroundColor: '#fff',
|
||||
borderWidth: 2,
|
||||
borderColor: '#aaa',
|
||||
clickable: false,
|
||||
hoverable: true
|
||||
},
|
||||
xaxis: {
|
||||
mode: "time",
|
||||
timeformat: "%b %y",
|
||||
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
|
||||
tickLength: 1,
|
||||
minTickSize: [1, "month"]
|
||||
},
|
||||
yaxes: [ { min: 0, tickDecimals: 2 } ]
|
||||
});
|
||||
|
||||
placeholder.resize();
|
||||
|
||||
<?php woocommerce_tooltip_js(); ?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
endif; // end POST check
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
jQuery("select.chosen_select").chosen();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -309,6 +309,134 @@ table.wc_status_table {
|
|||
}
|
||||
}
|
||||
|
||||
/* Coupon Lists */
|
||||
.column-coupon_code {
|
||||
line-height: 2.25em;
|
||||
}
|
||||
ul.wc_coupon_list, .column-coupon_code {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
zoom: 1;
|
||||
clear: both;
|
||||
.code {
|
||||
margin-right: 6px;
|
||||
}
|
||||
li.code {
|
||||
margin: 0 6px 12px 0 !important;
|
||||
}
|
||||
.code, .code a, .code span {
|
||||
&:before, &:after {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
width: 8px;
|
||||
height: 4px;
|
||||
background: #f7f7f7;
|
||||
-webkit-border-radius:2px;
|
||||
-moz-border-radius:2px;
|
||||
-o-border-radius:2px;
|
||||
border-radius:2px;
|
||||
-moz-box-shadow: 0 2px 0 0 rgba(255,255,255,0.3), inset 0 2px 0 0 rgba(0,0,0,0.1);
|
||||
-webkit-box-shadow: 0 2px 0 0 rgba(255,255,255,0.3), inset 0 2px 0 0 rgba(0,0,0,0.1);
|
||||
box-shadow: 0 2px 0 0 rgba(255,255,255,0.3), inset 0 2px 0 0 rgba(0,0,0,0.1);
|
||||
}
|
||||
}
|
||||
.code {
|
||||
overflow: hidden;
|
||||
vertical-align: middle;
|
||||
margin: 0 8px 0 0;
|
||||
|
||||
background: #ececec;
|
||||
color: #21759A;
|
||||
text-shadow: 0 1px 0 #ddd;
|
||||
|
||||
padding: 2px;
|
||||
position: relative;
|
||||
float: left;
|
||||
line-height: 1em;
|
||||
-moz-box-shadow: 0 2px 0 0 #dddddd;
|
||||
-webkit-box-shadow: 0 2px 0 0 #dddddd;
|
||||
box-shadow: 0 2px 0 0 #dddddd;
|
||||
font-weight: bold;
|
||||
|
||||
&:before {
|
||||
bottom: 5px;
|
||||
left: 0;
|
||||
margin: 0 0 0 -4px;
|
||||
}
|
||||
&:after {
|
||||
top: 5px;
|
||||
left: 0;
|
||||
margin: 0 0 0 -4px;
|
||||
}
|
||||
a, span {
|
||||
float: left;
|
||||
padding: 0 4px;
|
||||
color: #21759A;
|
||||
&:before {
|
||||
bottom: 5px;
|
||||
right: 0;
|
||||
margin: 0 -4px 0 0;
|
||||
}
|
||||
&:after {
|
||||
content: "";
|
||||
top: 5px;
|
||||
right: 0;
|
||||
margin: 0 -4px 0 0;
|
||||
}
|
||||
span {
|
||||
border: 1px dashed #ccc;
|
||||
padding: .5em 6px;
|
||||
-webkit-border-radius:2px;
|
||||
-moz-border-radius:2px;
|
||||
-o-border-radius:2px;
|
||||
border-radius:2px;
|
||||
&:before {
|
||||
top: 50%;
|
||||
left: 0;
|
||||
margin: -2px 0 0 -4px;
|
||||
}
|
||||
&:after {
|
||||
top: 50%;
|
||||
right: 0;
|
||||
margin: -2px -4px 0 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #975e83;
|
||||
color: #fff;
|
||||
text-shadow: 0 1px 0 #5a324b;
|
||||
a, span {
|
||||
color: #fff;
|
||||
span {
|
||||
border: 1px dashed #bb82a7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ul.wc_coupon_list_block {
|
||||
margin: 0;
|
||||
padding-bottom: 2px;
|
||||
li {
|
||||
border-top: 1px solid #fff;
|
||||
border-bottom: 1px solid #ccc;
|
||||
line-height: 2.5em;
|
||||
margin: 0;
|
||||
padding: .5em 0;
|
||||
}
|
||||
li:first-child {
|
||||
border-top:0;
|
||||
padding-top: 0;
|
||||
}
|
||||
li:last-child {
|
||||
border-bottom:0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Orders */
|
||||
.tablenav .actions {
|
||||
|
@ -560,7 +688,8 @@ table.wc_status_table {
|
|||
}
|
||||
.buttons {
|
||||
border-top: 1px solid white;
|
||||
padding: 0 10px 0 10px;
|
||||
padding: 1em 10px 1em 10px;
|
||||
margin: 0;
|
||||
text-align: right;
|
||||
.calc_line_taxes {
|
||||
float: left;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* The cart class also has a price calculation function which calls upon other classes to calculate totals.
|
||||
*
|
||||
* @class WC_Cart
|
||||
* @version 1.6.4
|
||||
* @version 2.0.0
|
||||
* @package WooCommerce/Classes
|
||||
* @author WooThemes
|
||||
*/
|
||||
|
@ -15,9 +15,12 @@ class WC_Cart {
|
|||
/** @var array Contains an array of cart items. */
|
||||
var $cart_contents;
|
||||
|
||||
/** @var array Contains an array of coupons applied to the cart. */
|
||||
/** @var array Contains an array of coupon codes applied to the cart. */
|
||||
var $applied_coupons;
|
||||
|
||||
/** @var array Contains an array of coupon code discounts after they have been applied. */
|
||||
var $coupon_discount_amounts;
|
||||
|
||||
/** @var float The total cost of the cart items. */
|
||||
var $cart_contents_total;
|
||||
|
||||
|
@ -119,8 +122,10 @@ class WC_Cart {
|
|||
global $woocommerce;
|
||||
|
||||
// Load the coupons
|
||||
if ( get_option( 'woocommerce_enable_coupons' ) == 'yes' )
|
||||
$this->applied_coupons = ( empty( $woocommerce->session->coupons ) ) ? array() : array_unique( array_filter( (array) $woocommerce->session->coupons ) );
|
||||
if ( get_option( 'woocommerce_enable_coupons' ) == 'yes' ) {
|
||||
$this->applied_coupons = ( empty( $woocommerce->session->coupon_codes ) ) ? array() : array_filter( (array) $woocommerce->session->coupon_codes );
|
||||
$this->coupon_discount_amounts = ( empty( $woocommerce->session->coupon_amounts ) ) ? array() : array_filter( (array) $woocommerce->session->coupon_amounts );
|
||||
}
|
||||
|
||||
// Load the cart
|
||||
if ( isset( $woocommerce->session->cart ) && is_array( $woocommerce->session->cart ) ) {
|
||||
|
@ -205,25 +210,26 @@ class WC_Cart {
|
|||
}
|
||||
}
|
||||
|
||||
$woocommerce->session->cart = $cart_session;
|
||||
$woocommerce->session->coupons = $this->applied_coupons;
|
||||
$woocommerce->session->cart = $cart_session;
|
||||
$woocommerce->session->coupon_codes = $this->applied_coupons;
|
||||
$woocommerce->session->coupon_amounts = $this->coupon_discount_amounts;
|
||||
|
||||
// Store totals to avoid re-calc on page load
|
||||
$woocommerce->session->cart_contents_total = $this->cart_contents_total;
|
||||
$woocommerce->session->cart_contents_total = $this->cart_contents_total;
|
||||
$woocommerce->session->cart_contents_weight = $this->cart_contents_weight;
|
||||
$woocommerce->session->cart_contents_count = $this->cart_contents_count;
|
||||
$woocommerce->session->cart_contents_tax = $this->cart_contents_tax;
|
||||
$woocommerce->session->total = $this->total;
|
||||
$woocommerce->session->subtotal = $this->subtotal;
|
||||
$woocommerce->session->subtotal_ex_tax = $this->subtotal_ex_tax;
|
||||
$woocommerce->session->tax_total = $this->tax_total;
|
||||
$woocommerce->session->shipping_taxes = $this->shipping_taxes;
|
||||
$woocommerce->session->taxes = $this->taxes;
|
||||
$woocommerce->session->discount_cart = $this->discount_cart;
|
||||
$woocommerce->session->discount_total = $this->discount_total;
|
||||
$woocommerce->session->shipping_total = $this->shipping_total;
|
||||
$woocommerce->session->shipping_tax_total = $this->shipping_tax_total;
|
||||
$woocommerce->session->shipping_label = $this->shipping_label;
|
||||
$woocommerce->session->cart_contents_count = $this->cart_contents_count;
|
||||
$woocommerce->session->cart_contents_tax = $this->cart_contents_tax;
|
||||
$woocommerce->session->total = $this->total;
|
||||
$woocommerce->session->subtotal = $this->subtotal;
|
||||
$woocommerce->session->subtotal_ex_tax = $this->subtotal_ex_tax;
|
||||
$woocommerce->session->tax_total = $this->tax_total;
|
||||
$woocommerce->session->shipping_taxes = $this->shipping_taxes;
|
||||
$woocommerce->session->taxes = $this->taxes;
|
||||
$woocommerce->session->discount_cart = $this->discount_cart;
|
||||
$woocommerce->session->discount_total = $this->discount_total;
|
||||
$woocommerce->session->shipping_total = $this->shipping_total;
|
||||
$woocommerce->session->shipping_tax_total = $this->shipping_tax_total;
|
||||
$woocommerce->session->shipping_label = $this->shipping_label;
|
||||
|
||||
if ( get_current_user_id() )
|
||||
$this->persistent_cart_update();
|
||||
|
@ -244,7 +250,7 @@ class WC_Cart {
|
|||
$this->cart_contents = array();
|
||||
$this->reset();
|
||||
|
||||
unset( $woocommerce->session->order_awaiting_payment, $woocommerce->session->coupons, $woocommerce->session->cart );
|
||||
unset( $woocommerce->session->order_awaiting_payment, $woocommerce->session->coupon_codes, $woocommerce->session->coupon_amounts, $woocommerce->session->cart );
|
||||
|
||||
if ( $clear_persistent_cart && get_current_user_id() )
|
||||
$this->persistent_cart_destroy();
|
||||
|
@ -332,8 +338,9 @@ class WC_Cart {
|
|||
|
||||
// Remove the coupon
|
||||
unset( $this->applied_coupons[ $key ] );
|
||||
$woocommerce->session->coupons = $this->applied_coupons;
|
||||
$woocommerce->session->refresh_totals = true;
|
||||
|
||||
$woocommerce->session->coupon_codes = $this->applied_coupons;
|
||||
$woocommerce->session->refresh_totals = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -407,8 +414,9 @@ class WC_Cart {
|
|||
$woocommerce->add_error( sprintf( __( 'Sorry, it seems the coupon "%s" is not yours - it has now been removed from your order.', 'woocommerce' ), $code ) );
|
||||
// Remove the coupon
|
||||
unset( $this->applied_coupons[ $key ] );
|
||||
$woocommerce->session->coupons = $this->applied_coupons;
|
||||
$woocommerce->session->refresh_totals = true;
|
||||
|
||||
$woocommerce->session->coupon_codes = $this->applied_coupons;
|
||||
$woocommerce->session->refresh_totals = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -945,13 +953,17 @@ class WC_Cart {
|
|||
|
||||
if ( $add_totals ) {
|
||||
$this->discount_cart = $this->discount_cart + ( $discount_amount * $values['quantity'] );
|
||||
$this->coupon_discount_amounts[ $code ] = ( $discount_amount * $values['quantity'] );
|
||||
}
|
||||
|
||||
} elseif ( $coupon->type == 'percent_product' ) {
|
||||
|
||||
$percent_discount = ( $values['data']->get_price_excluding_tax() / 100 ) * $coupon->amount;
|
||||
|
||||
if ( $add_totals ) $this->discount_cart = $this->discount_cart + ( $percent_discount * $values['quantity'] );
|
||||
if ( $add_totals ) {
|
||||
$this->discount_cart = $this->discount_cart + ( $percent_discount * $values['quantity'] );
|
||||
$this->coupon_discount_amounts[ $code ] = ( $percent_discount * $values['quantity'] );
|
||||
}
|
||||
|
||||
$price = $price - $percent_discount;
|
||||
|
||||
|
@ -1002,7 +1014,10 @@ class WC_Cart {
|
|||
if ( $price < 0 ) $price = 0;
|
||||
|
||||
// Add coupon to discount total (once, since this is a fixed cart discount and we don't want rounding issues)
|
||||
if ( $add_totals ) $this->discount_cart = $this->discount_cart + ( ( $discount_amount * $values['quantity'] ) / 100 );
|
||||
if ( $add_totals ) {
|
||||
$this->discount_cart = $this->discount_cart + ( ( $discount_amount * $values['quantity'] ) / 100 );
|
||||
$this->coupon_discount_amounts[ $code ] = ( ( $discount_amount * $values['quantity'] ) / 100 );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
@ -1010,8 +1025,10 @@ class WC_Cart {
|
|||
|
||||
$percent_discount = round( ( $values['data']->get_price() / 100 ) * $coupon->amount, $this->dp );
|
||||
|
||||
if ( $add_totals )
|
||||
if ( $add_totals ) {
|
||||
$this->discount_cart = $this->discount_cart + ( $percent_discount * $values['quantity'] );
|
||||
$this->coupon_discount_amounts[ $code ] = ( $percent_discount * $values['quantity'] );
|
||||
}
|
||||
|
||||
$price = $price - $percent_discount;
|
||||
|
||||
|
@ -1091,8 +1108,11 @@ class WC_Cart {
|
|||
|
||||
$this->discount_total = $this->discount_total + ( $discount_amount * $values['quantity'] );
|
||||
|
||||
$this->coupon_discount_amounts[ $code ] = ( $discount_amount * $values['quantity'] );
|
||||
|
||||
} elseif ( $coupon->type == 'percent_product' ) {
|
||||
$this->discount_total = $this->discount_total + round( ( $price / 100 ) * $coupon->amount, $this->dp );
|
||||
$this->coupon_discount_amounts[ $code ] = round( ( $price / 100 ) * $coupon->amount, $this->dp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1122,6 +1142,8 @@ class WC_Cart {
|
|||
|
||||
$this->discount_total = $this->discount_total + $coupon->amount;
|
||||
|
||||
$this->coupon_discount_amounts[ $code ] = $coupon->amount;
|
||||
|
||||
break;
|
||||
|
||||
case "percent" :
|
||||
|
@ -1130,6 +1152,8 @@ class WC_Cart {
|
|||
|
||||
$this->discount_total = $this->discount_total + round( $percent_discount, $this->dp );
|
||||
|
||||
$this->coupon_discount_amounts[ $code ] = round( $percent_discount, $this->dp );
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -1726,7 +1750,7 @@ class WC_Cart {
|
|||
}
|
||||
}
|
||||
|
||||
$woocommerce->session->coupons = $this->applied_coupons;
|
||||
$woocommerce->session->coupon_codes = $this->applied_coupons;
|
||||
} elseif ( $type == 2 ) {
|
||||
if ( $this->applied_coupons ) {
|
||||
foreach ( $this->applied_coupons as $index => $code ) {
|
||||
|
@ -1735,9 +1759,9 @@ class WC_Cart {
|
|||
}
|
||||
}
|
||||
|
||||
$woocommerce->session->coupons = $this->applied_coupons;
|
||||
$woocommerce->session->coupon_codes = $this->applied_coupons;
|
||||
} else {
|
||||
unset( $woocommerce->session->coupons );
|
||||
unset( $woocommerce->session->coupon_codes, $woocommerce->session->coupon_amounts );
|
||||
$this->applied_coupons = array();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -580,7 +580,22 @@ class WC_Checkout {
|
|||
woocommerce_add_order_item_meta( $item_id, 'tax_amount', woocommerce_clean( isset( $woocommerce->cart->taxes[ $key ] ) ? $woocommerce->cart->taxes[ $key ] : 0 ) );
|
||||
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_clean( isset( $woocommerce->cart->shipping_taxes[ $key ] ) ? $woocommerce->cart->shipping_taxes[ $key ] : 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Store coupons
|
||||
if ( $applied_coupons = $woocommerce->cart->get_applied_coupons() ) {
|
||||
foreach ( $applied_coupons as $code ) {
|
||||
|
||||
$item_id = woocommerce_add_order_item( $order_id, array(
|
||||
'order_item_name' => $code,
|
||||
'order_item_type' => 'coupon'
|
||||
) );
|
||||
|
||||
// Add line item meta
|
||||
if ( $item_id ) {
|
||||
woocommerce_add_order_item_meta( $item_id, 'discount_amount', isset( $woocommerce->cart->coupon_discount_amounts[ $code ] ) ? $woocommerce->cart->coupon_discount_amounts[ $code ] : 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save other order meta fields
|
||||
|
@ -612,17 +627,6 @@ class WC_Checkout {
|
|||
// Order status
|
||||
wp_set_object_terms( $order_id, 'pending', 'shop_order_status' );
|
||||
|
||||
// Discount code meta
|
||||
if ( $applied_coupons = $woocommerce->cart->get_applied_coupons() ) {
|
||||
|
||||
update_post_meta( $order_id, 'coupons', implode(', ', $applied_coupons) );
|
||||
|
||||
if ( empty( $order ) )
|
||||
$order = new WC_Order( $order_id );
|
||||
|
||||
$order->add_order_note( sprintf( __( 'Coupon Code Used: %s', 'woocommerce' ), implode(', ', $applied_coupons ) ) );
|
||||
}
|
||||
|
||||
// Order is saved
|
||||
do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );
|
||||
|
||||
|
|
|
@ -106,6 +106,8 @@ class WC_Coupon {
|
|||
|
||||
if ( $coupon_id )
|
||||
$coupon = get_post( $coupon_id );
|
||||
else
|
||||
return false;
|
||||
|
||||
$coupon->post_title = apply_filters( 'woocommerce_coupon_code', $coupon->post_title );
|
||||
|
||||
|
|
|
@ -1317,16 +1317,21 @@ class WC_Order {
|
|||
|
||||
|
||||
/**
|
||||
* Increase applied coupon counts
|
||||
* Get coupon codes only.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function get_used_coupons() {
|
||||
|
||||
$coupons = get_post_meta( $this->id, 'coupons', true );
|
||||
$codes = array();
|
||||
$coupons = $this->get_items( 'coupon' );
|
||||
|
||||
return array_map( 'trim', explode( ',', $coupons ) );
|
||||
foreach ( $coupons as $item_id => $item ) {
|
||||
$codes[] = trim( $item['name'] );
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ class WC_Emails {
|
|||
function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
|
||||
|
||||
$meta = array();
|
||||
$show_fields = apply_filters( 'woocommerce_email_order_meta_keys', array( 'coupons' ), $sent_to_admin );
|
||||
$show_fields = apply_filters( 'woocommerce_email_order_meta_keys', array(), $sent_to_admin );
|
||||
|
||||
if ( $order->customer_note )
|
||||
$meta[ __( 'Note', 'woocommerce' ) ] = wptexturize( $order->customer_note );
|
||||
|
|
|
@ -188,6 +188,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Feature - Taxes can be based on shipping, billing, or shop base.
|
||||
* Feature - Filter coupons in admin by type.
|
||||
* Feature - Append view cart link on ajax buttons.
|
||||
* Feature - Revised the way coupons are stored per order and added new coupon reports on usage.
|
||||
|
||||
* Templating - Revised pagination, sorting areas (sorting is now above products, numbered pagination below) and added a result count.
|
||||
* Templating - email-order-items.php change get_downloadable_file_url() to get_downloadable_file_urls() to support multiple files.
|
||||
|
|
Loading…
Reference in New Issue