WC_Report_Coupon_Usage::coupons_widget() │ public │ WC 1.0
Output coupons widget.
Метод класса: WC_Report_Coupon_Usage{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$WC_Report_Coupon_Usage = new WC_Report_Coupon_Usage(); $WC_Report_Coupon_Usage->coupons_widget();
Код WC_Report_Coupon_Usage::coupons_widget() WC Report Coupon Usage::coupons widget WC 9.7.1
<?php public function coupons_widget() { ?> <h4 class="section_title"><span><?php esc_html_e( 'Filter by coupon', 'woocommerce' ); ?></span></h4> <div class="section"> <form method="GET"> <div> <?php $used_coupons = $this->get_order_report_data( array( 'data' => array( 'order_item_name' => array( 'type' => 'order_item', 'order_item_type' => 'coupon', 'function' => '', 'distinct' => true, 'name' => 'order_item_name', ), ), 'where' => array( array( 'key' => 'order_item_type', 'value' => 'coupon', 'operator' => '=', ), ), 'query_type' => 'get_col', 'filter_range' => false, ) ); if ( ! empty( $used_coupons ) && is_array( $used_coupons ) ) : ?> <select id="coupon_codes" name="coupon_codes" class="wc-enhanced-select" data-placeholder="<?php esc_attr_e( 'Choose coupons…', 'woocommerce' ); ?>" style="width:100%;"> <option value=""><?php esc_html_e( 'All coupons', 'woocommerce' ); ?></option> <?php foreach ( $used_coupons as $coupon ) { echo '<option value="' . esc_attr( $coupon ) . '"' . wc_selected( $coupon, $this->coupon_codes ) . '>' . esc_html( $coupon ) . '</option>'; } ?> </select> <?php // @codingStandardsIgnoreStart ?> <button type="submit" class="submit button" value="<?php esc_attr_e( 'Show', 'woocommerce' ); ?>"><?php esc_html_e( 'Show', 'woocommerce' ); ?></button> <input type="hidden" name="range" value="<?php echo ( ! empty( $_GET['range'] ) ) ? esc_attr( wp_unslash( $_GET['range'] ) ) : ''; ?>" /> <input type="hidden" name="start_date" value="<?php echo ( ! empty( $_GET['start_date'] ) ) ? esc_attr( wp_unslash( $_GET['start_date'] ) ) : ''; ?>" /> <input type="hidden" name="end_date" value="<?php echo ( ! empty( $_GET['end_date'] ) ) ? esc_attr( wp_unslash( $_GET['end_date'] ) ) : ''; ?>" /> <input type="hidden" name="page" value="<?php echo ( ! empty( $_GET['page'] ) ) ? esc_attr( wp_unslash( $_GET['page'] ) ) : ''; ?>" /> <input type="hidden" name="tab" value="<?php echo ( ! empty( $_GET['tab'] ) ) ? esc_attr( wp_unslash( $_GET['tab'] ) ) : ''; ?>" /> <input type="hidden" name="report" value="<?php echo ( ! empty( $_GET['report'] ) ) ? esc_attr( wp_unslash( $_GET['report'] ) ) : ''; ?>" /> <?php // @codingStandardsIgnoreEnd ?> <?php else : ?> <span><?php esc_html_e( 'No used coupons found', 'woocommerce' ); ?></span> <?php endif; ?> </div> </form> </div> <h4 class="section_title"><span><?php esc_html_e( 'Most popular', 'woocommerce' ); ?></span></h4> <div class="section"> <table cellspacing="0"> <?php $most_popular = $this->get_order_report_data( array( 'data' => array( 'order_item_name' => array( 'type' => 'order_item', 'order_item_type' => 'coupon', 'function' => '', 'name' => 'coupon_code', ), 'order_item_id' => array( 'type' => 'order_item', 'order_item_type' => 'coupon', 'function' => 'COUNT', 'name' => 'coupon_count', ), ), 'where' => array( array( 'type' => 'order_item', 'key' => 'order_item_type', 'value' => 'coupon', 'operator' => '=', ), ), 'order_by' => 'coupon_count DESC', 'group_by' => 'order_item_name', 'limit' => 12, 'query_type' => 'get_results', 'filter_range' => true, ) ); if ( ! empty( $most_popular ) && is_array( $most_popular ) ) { foreach ( $most_popular as $coupon ) { echo '<tr class="' . ( in_array( $coupon->coupon_code, $this->coupon_codes ) ? 'active' : '' ) . '"> <td class="count" width="1%">' . esc_html( $coupon->coupon_count ) . '</td> <td class="name"><a href="' . esc_url( add_query_arg( 'coupon_codes', $coupon->coupon_code ) ) . '">' . esc_html( $coupon->coupon_code ) . '</a></td> </tr>'; } } else { echo '<tr><td colspan="2">' . esc_html__( 'No coupons found in range', 'woocommerce' ) . '</td></tr>'; } ?> </table> </div> <h4 class="section_title"><span><?php esc_html_e( 'Most discount', 'woocommerce' ); ?></span></h4> <div class="section"> <table cellspacing="0"> <?php $most_discount = $this->get_order_report_data( array( 'data' => array( 'order_item_name' => array( 'type' => 'order_item', 'order_item_type' => 'coupon', 'function' => '', 'name' => 'coupon_code', ), 'discount_amount' => array( 'type' => 'order_item_meta', 'order_item_type' => 'coupon', 'function' => 'SUM', 'name' => 'discount_amount', ), ), 'where' => array( array( 'type' => 'order_item', 'key' => 'order_item_type', 'value' => 'coupon', 'operator' => '=', ), ), 'order_by' => 'discount_amount DESC', 'group_by' => 'order_item_name', 'limit' => 12, 'query_type' => 'get_results', 'filter_range' => true, ) ); if ( ! empty( $most_discount ) && is_array( $most_discount ) ) { foreach ( $most_discount as $coupon ) { // @codingStandardsIgnoreStart echo '<tr class="' . ( in_array( $coupon->coupon_code, $this->coupon_codes ) ? 'active' : '' ) . '"> <td class="count" width="1%">' . wc_price( $coupon->discount_amount ) . '</td> <td class="name"><a href="' . esc_url( add_query_arg( 'coupon_codes', $coupon->coupon_code ) ) . '">' . esc_html( $coupon->coupon_code ) . '</a></td> </tr>'; // @codingStandardsIgnoreEnd } } else { echo '<tr><td colspan="3">' . esc_html__( 'No coupons found in range', 'woocommerce' ) . '</td></tr>'; } ?> </table> </div> <script type="text/javascript"> jQuery( '.section_title' ).on( 'click', function() { var next_section = jQuery( this ).next( '.section' ); if ( jQuery( next_section ).is( ':visible' ) ) { return false; } jQuery( '.section:visible' ).slideUp(); jQuery( '.section_title' ).removeClass( 'open' ); jQuery( this ).addClass( 'open' ).next( '.section' ).slideDown(); return false; } ); jQuery( '.section' ).slideUp( 100, function() { <?php if ( empty( $this->coupon_codes ) ) : ?> jQuery( '.section_title:eq(1)' ).trigger( 'click' ); <?php else : ?> jQuery( '.section_title:eq(0)' ).trigger( 'click' ); <?php endif; ?> } ); </script> <?php }