Advertisement
Guest User

BPA

a guest
Feb 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.02 KB | None | 0 0
  1. <?php
  2.  
  3. add_filter('woo_pdf_totals', 'woo_pdf_change_totals');
  4.  
  5. function woo_pdf_change_totals($totals) {
  6.    
  7.   $taxonomy     = 'product_cat';
  8.   $orderby      = 'name';  
  9.   $show_count   = 0;      // 1 for yes, 0 for no
  10.   $pad_counts   = 0;      // 1 for yes, 0 for no
  11.   $hierarchical = 1;      // 1 for yes, 0 for no  
  12.   $title        = '';  
  13.   $empty        = 0;
  14.  
  15.   $args = array(
  16.          'taxonomy'     => $taxonomy,
  17.          'orderby'      => $orderby,
  18.          'show_count'   => $show_count,
  19.          'pad_counts'   => $pad_counts,
  20.          'hierarchical' => $hierarchical,
  21.          'title_li'     => $title,
  22.          'hide_empty'   => $empty
  23.   );
  24.  $all_categories = get_categories( $args );
  25.      
  26.         if($all_categories) {
  27.             foreach($all_categories as $sub_category) {
  28.                 $category =  $sub_category->name ;
  29.             }
  30.         }    
  31.    
  32.         if ($category == 'korting25') {
  33.             (int)$korting = 0.25;
  34.             $kortingNaam = 'Korting 25%';
  35.         } else if ($category == 'korting30') {
  36.             (int)$korting = 0.30;
  37.             $kortingNaam = 'Korting 30%';
  38.         } else {
  39.             (int)$korting = 0.2;
  40.         }
  41.    
  42.        $order_pdf_total = $totals['subtotal']['value'];
  43.        $order_pdf_discount = $totals['subtotal']['value'] / 121 * 100 * $korting;
  44.        $order_pdf_discounted = $totals['subtotal']['value'] /121 * 100 - $order_pdf_discount;
  45.    
  46.        $new_totals = array(
  47.    
  48.        $totals['total'] = array(
  49.           'name'  => "Totaal",
  50.           'value' => (double) $order_pdf_total,
  51.        ),
  52.    
  53.        $totals['discount'] = array(
  54.            'name'  => $kortingNaam,
  55.            'value' => (double) $order_pdf_discount,
  56.        ),
  57.    
  58.        $totals['discounted'] = array(
  59.            'name'  => "Totaal incl. 20% korting",
  60.            'value' => (double) $order_pdf_discounted,
  61.        )       
  62.            
  63.     );
  64.         return $new_totals;
  65.  
  66. }
  67.  
  68. /* Discount in mail. */
  69. add_action('woocommerce_email_order_details', 'new_order_custom_email_notification', 20, 4 );
  70. function new_order_custom_email_notification( $order, $sent_to_admin, $plain_text, $email )
  71. {
  72.     // Only for  "New order" email notifications (admin)
  73.     if( $email->id != 'new_order' ) return;
  74.  
  75.     $order_total = floatval($order->get_subtotal());
  76.     $order_total_discount =  $order_total * 0.2;
  77.     $order_total_discounted =  $order_total - $order_total_discount;
  78.  
  79.     // CSS style
  80.     $styles = '<style>
  81.       .discount-info table{width: 100%; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif;
  82.           color: #737373; border: 1px solid #e4e4e4; margin-bottom:8px;}
  83.       .discount-info table th, table.tracking-info td{text-align: left; border-top-width: 4px;
  84.           color: #737373; border: 1px solid #e4e4e4; padding: 12px; width:58%;}
  85.       .discount-info table td{text-align: left; border-top-width: 4px; color: #737373; border: 1px solid #e4e4e4; padding: 12px;}
  86.   </style>';
  87.  
  88.     // HTML Structure
  89.     $html_output = '<h2>'.__('Inkoopprijs').'</h2>
  90.   <div class="discount-info">
  91.       <table cellspacing="0" cellpadding="6">
  92.           <tr>
  93.               <th>' . __('Totaal') . '</th>
  94.               <td>' . wc_price($order_total) . '</td>
  95.           </tr>
  96.           <tr>
  97.               <th>' . __('Korting 20%') . '</th>
  98.               <td>' . wc_price($order_total_discount) . '</td>
  99.           </tr>
  100.           <tr>
  101.               <th>' . __('Totaal incl. 20% korting') . '</th>
  102.               <td>' . wc_price($order_total_discounted) . '</td>
  103.           </tr>
  104.       </table>
  105.   </div><br>'; // HTML (end)
  106.    
  107.         // Output CSS + HTML
  108.     echo $styles . $html_output;
  109.    
  110. }
  111.  
  112. define('EPICO_THEME_SLUG', 'Ep');
  113. define('EPICOMEDIA_THEME_SLUG', 'vitrine');
  114. define('VITRINE_THEME_SLUG', 'vitrine');
  115.  
  116. /**************************************************
  117.     FOLDERS
  118. **************************************************/
  119.  
  120. define('EPICO_THEME_DIR',         get_parent_theme_file_path());
  121. define('EPICO_THEME_LIB',         EPICO_THEME_DIR . '/lib');
  122. define('EPICO_THEME_PLUGINS',     EPICO_THEME_DIR . '/plugins');
  123. define('EPICO_THEME_CSS',         EPICO_THEME_DIR . '/assets/css');
  124.  
  125. /**************************************************
  126.     FOLDER URI
  127. **************************************************/
  128.  
  129. define('EPICO_THEME_URI',              get_parent_theme_file_uri());
  130. define('EPICO_THEME_LIB_URI',         EPICO_THEME_URI . '/lib');
  131. define('EPICO_THEME_ASSETS_URI',      EPICO_THEME_URI     . '/assets');
  132. define('EPICO_THEME_IMAGES_URI',      EPICO_THEME_ASSETS_URI . '/img');
  133.  
  134. /**************************************************
  135.     Text Domain
  136. **************************************************/
  137.  
  138. load_theme_textdomain( 'vitrine' , EPICO_THEME_DIR . '/languages' );
  139.  
  140. /**************************************************
  141.     Content Width
  142. **************************************************/
  143.  
  144. if ( !isset( $content_width ) ) $content_width = 1170;
  145.  
  146. /**************************************************
  147.     LIBRARIES
  148. **************************************************/
  149.  
  150. require_once(EPICO_THEME_LIB . '/framework.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement