Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function electro_onsale_product( $args = array() ) {
- if ( is_woocommerce_activated() ) {
- $defaults = array(
- 'section_title' => wp_kses_post( __( '<span class="highlight">Special</span> Offer', 'electro' ) ),
- 'section_class' => '',
- 'show_savings' => true,
- 'savings_in' => 'amount',
- 'savings_text' => esc_html__( 'Save', 'electro' ),
- );
- if ( isset( $args['product_choice'] ) ) {
- switch( $args['product_choice'] ) {
- case 'random':
- $args['orderby'] = 'rand';
- break;
- case 'recent':
- $args['orderby'] = 'date';
- $args['order'] = 'DESC';
- break;
- case 'specific':
- $args['orderby'] = 'post__in';
- $args['ids'] = $args['product_id'];
- $args['post__in'] = array_map( 'trim', explode( ',', $args['product_id'] ) );
- break;
- }
- }
- $args = wp_parse_args( array( 'per_page' => 1 ), $args );
- $args = wp_parse_args( $args, $defaults );
- $products = Electro_Products::sale_products( $args );
- extract( $args );
- if ( $products->have_posts() ) {
- while ( $products->have_posts() ) : $products->the_post();
- ?>
- <section class="section-onsale-product <?php echo esc_attr( $section_class ); ?>">
- <?php if ( ! empty ( $section_title ) || $show_savings ) : ?>
- <header>
- <?php if ( ! empty ( $section_title ) ) : ?>
- <h2 class="h1"><?php echo wp_kses_post( $section_title ); ?></h2>
- <?php endif ; ?>
- <?php if ( $show_savings ) : ?>
- <?php global $product; ?>
- <?php if( $product->is_on_sale() ) { ?>
- <div class="savings">
- <span class="savings-text">
- <?php
- echo sprintf( '%s %s', $savings_text, Electro_WC_Helper::get_savings_on_sale( $product, $savings_in ) );
- ?>
- </span>
- </div>
- <?php } ?>
- <?php endif; ?>
- </header>
- <?php endif; ?>
- <div class="onsale-products">
- <?php wc_get_template_part( 'templates/contents/content', 'onsale-product' ); ?>
- </div>
- </section>
- <?php
- endwhile;
- woocommerce_reset_loop();
- wp_reset_postdata();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement