Use CRUD in coupons list
This commit is contained in:
parent
4124d41e46
commit
b409c1edef
|
@ -450,28 +450,29 @@ class WC_Admin_Post_Types {
|
|||
* @param string $column
|
||||
*/
|
||||
public function render_shop_coupon_columns( $column ) {
|
||||
global $post;
|
||||
global $post, $the_coupon;
|
||||
|
||||
if ( empty( $the_coupon ) || $the_coupon->get_id() !== $post->ID ) {
|
||||
$the_coupon = new WC_Coupon( $post->ID );
|
||||
}
|
||||
|
||||
switch ( $column ) {
|
||||
case 'coupon_code' :
|
||||
$edit_link = get_edit_post_link( $post->ID );
|
||||
$title = _draft_or_post_title();
|
||||
$title = $the_coupon->get_code();
|
||||
|
||||
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) . '">' . esc_html( $title ) . '</a>';
|
||||
|
||||
_post_states( $post );
|
||||
|
||||
echo '</strong>';
|
||||
break;
|
||||
case 'type' :
|
||||
echo esc_html( wc_get_coupon_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
|
||||
echo esc_html( wc_get_coupon_type( $the_coupon->get_discount_type() ) );
|
||||
break;
|
||||
case 'amount' :
|
||||
echo esc_html( get_post_meta( $post->ID, 'coupon_amount', true ) );
|
||||
echo esc_html( $the_coupon->get_amount() );
|
||||
break;
|
||||
case 'products' :
|
||||
$product_ids = get_post_meta( $post->ID, 'product_ids', true );
|
||||
$product_ids = $product_ids ? array_map( 'absint', explode( ',', $product_ids ) ) : array();
|
||||
$product_ids = $the_coupon->get_product_ids();
|
||||
|
||||
if ( sizeof( $product_ids ) > 0 ) {
|
||||
echo esc_html( implode( ', ', $product_ids ) );
|
||||
|
@ -480,7 +481,7 @@ class WC_Admin_Post_Types {
|
|||
}
|
||||
break;
|
||||
case 'usage_limit' :
|
||||
$usage_limit = get_post_meta( $post->ID, 'usage_limit', true );
|
||||
$usage_limit = $the_coupon->get_usage_limit();
|
||||
|
||||
if ( $usage_limit ) {
|
||||
echo esc_html( $usage_limit );
|
||||
|
@ -489,28 +490,28 @@ class WC_Admin_Post_Types {
|
|||
}
|
||||
break;
|
||||
case 'usage' :
|
||||
$usage_count = absint( get_post_meta( $post->ID, 'usage_count', true ) );
|
||||
$usage_limit = esc_html( get_post_meta( $post->ID, 'usage_limit', true ) );
|
||||
$usage_url = sprintf( '<a href="%s">%s</a>', admin_url( sprintf( 'edit.php?s=%s&post_status=all&post_type=shop_order', esc_html( $post->post_title ) ) ), $usage_count );
|
||||
$usage_count = $the_coupon->get_usage_count();
|
||||
$usage_limit = $the_coupon->get_usage_limit();
|
||||
$usage_url = sprintf( '<a href="%s">%s</a>', admin_url( sprintf( 'edit.php?s=%s&post_status=all&post_type=shop_order', esc_html( $post->post_title ) ) ), esc_html( $usage_count ) );
|
||||
|
||||
/* translators: 1: count 2: limit */
|
||||
printf(
|
||||
__( '%1$s / %2$s', 'woocommerce' ),
|
||||
$usage_url,
|
||||
$usage_limit ? $usage_limit : '∞'
|
||||
esc_html( $usage_limit ? $usage_limit : '∞' )
|
||||
);
|
||||
break;
|
||||
case 'expiry_date' :
|
||||
$expiry_date = get_post_meta( $post->ID, 'expiry_date', true );
|
||||
$expiry_date = $the_coupon->get_date_expires();
|
||||
|
||||
if ( $expiry_date ) {
|
||||
echo esc_html( date_i18n( 'F j, Y', strtotime( $expiry_date ) ) );
|
||||
echo esc_html( date_i18n( 'F j, Y', $expiry_date ) );
|
||||
} else {
|
||||
echo '–';
|
||||
}
|
||||
break;
|
||||
case 'description' :
|
||||
echo wp_kses_post( $post->post_excerpt );
|
||||
echo wp_kses_post( $the_coupon->get_description() ? $the_coupon->get_description() : '–' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue