Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. function electro_onsale_product( $args = array() ) {
  2. if ( is_woocommerce_activated() ) {
  3.  
  4. $defaults = array(
  5. 'section_title' => wp_kses_post( __( '<span class="highlight">Special</span> Offer', 'electro' ) ),
  6. 'section_class' => '',
  7. 'show_savings' => true,
  8. 'savings_in' => 'amount',
  9. 'savings_text' => esc_html__( 'Save', 'electro' ),
  10. );
  11.  
  12. if ( isset( $args['product_choice'] ) ) {
  13. switch( $args['product_choice'] ) {
  14. case 'random':
  15. $args['orderby'] = 'rand';
  16. break;
  17. case 'recent':
  18. $args['orderby'] = 'date';
  19. $args['order'] = 'DESC';
  20. break;
  21. case 'specific':
  22. $args['orderby'] = 'post__in';
  23. $args['ids'] = $args['product_id'];
  24. $args['post__in'] = array_map( 'trim', explode( ',', $args['product_id'] ) );
  25. break;
  26. }
  27. }
  28.  
  29. $args = wp_parse_args( array( 'per_page' => 1 ), $args );
  30. $args = wp_parse_args( $args, $defaults );
  31. $products = Electro_Products::sale_products( $args );
  32.  
  33. extract( $args );
  34.  
  35. if ( $products->have_posts() ) {
  36.  
  37. while ( $products->have_posts() ) : $products->the_post();
  38. ?>
  39. <section class="section-onsale-product <?php echo esc_attr( $section_class ); ?>">
  40.  
  41. <?php if ( ! empty ( $section_title ) || $show_savings ) : ?>
  42.  
  43. <header>
  44.  
  45. <?php if ( ! empty ( $section_title ) ) : ?>
  46.  
  47. <h2 class="h1"><?php echo wp_kses_post( $section_title ); ?></h2>
  48.  
  49. <?php endif ; ?>
  50.  
  51. <?php if ( $show_savings ) : ?>
  52.  
  53. <?php global $product; ?>
  54.  
  55. <?php if( $product->is_on_sale() ) { ?>
  56. <div class="savings">
  57. <span class="savings-text">
  58. <?php
  59. echo sprintf( '%s %s', $savings_text, Electro_WC_Helper::get_savings_on_sale( $product, $savings_in ) );
  60. ?>
  61. </span>
  62. </div>
  63.  
  64. <?php } ?>
  65.  
  66. <?php endif; ?>
  67.  
  68. </header>
  69.  
  70. <?php endif; ?>
  71. <div class="onsale-products">
  72. <?php wc_get_template_part( 'templates/contents/content', 'onsale-product' ); ?>
  73. </div>
  74.  
  75. </section>
  76.  
  77. <?php
  78.  
  79. endwhile;
  80.  
  81. woocommerce_reset_loop();
  82. wp_reset_postdata();
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement