Using new coupon_info metadata, if it exists, to determine the actual coupon id (#48262)
* Using new coupon_info metadata to determine the actual coupon id Changes to make use of the new coupon_info meta data, if it exists, to determine the actually-used coupon. If coupon_info meta data doesn't exist, I'm also adding an extra filter so, in case there are more than one active coupons with the same name, we filter out the ones that were created after the order. --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Néstor Soriano <konamiman@konamiman.com>
This commit is contained in:
parent
72112bd5d4
commit
7f89cd5090
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix the order-items view for coupons, so we show the actually-used coupon info, if it exists.
|
|
@ -118,7 +118,13 @@ if ( wc_tax_enabled() ) {
|
|||
<li><strong><?php esc_html_e( 'Coupon(s)', 'woocommerce' ); ?></strong></li>
|
||||
<?php
|
||||
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->get_code() ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$coupon_info = $item->get_meta( 'coupon_info' );
|
||||
if ( $coupon_info ) {
|
||||
$coupon_info = json_decode( $coupon_info, true );
|
||||
$post_id = $coupon_info[0]; //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
} else {
|
||||
$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' AND post_date < %s LIMIT 1;", $item->get_code(), $order->get_date_created()->format( 'Y-m-d H:i:s' ) ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
}
|
||||
$class = $order->is_editable() ? 'code editable' : 'code';
|
||||
?>
|
||||
<li class="<?php echo esc_attr( $class ); ?>">
|
||||
|
|
Loading…
Reference in New Issue