1. <?php
  2. #-----------------------------------------
  3. #   RT-Theme woo-integration.php
  4. #   version: 1.0
  5. #-----------------------------------------
  6.  
  7.  
  8.  
  9. #-----------------------------------------
  10. #   remove woo actions
  11. #-----------------------------------------
  12.  
  13. global $woocommerce, $suffix;
  14. //remove woo styles
  15. if(!is_admin()){
  16.     //define('WOOCOMMERCE_USE_CSS', false);
  17.     add_action("wp_enqueue_scripts", "rt_remove_woo_stlyes");
  18. }
  19.  
  20.  
  21.  
  22. //wrapper removes
  23. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); // remove woo main content
  24. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); // remove woo main content end
  25.  
  26.  
  27. //breadcrumb
  28. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );    // remove breadcrumb
  29.  
  30. //pagination
  31. remove_action( 'woocommerce_pagination', 'woocommerce_pagination', 10 ); // remove woo pagination
  32.  
  33. //remove woo sidebar
  34. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10); // remove woo sidebar
  35.  
  36. //catalog ordering
  37. remove_action( 'woocommerce_pagination', 'woocommerce_catalog_ordering', 20 ); // remove catalog ordering
  38.  
  39. //remove woo thumbs
  40. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  41.  
  42. // remove single product title
  43. remove_action( "woocommerce_single_product_summary","woocommerce_template_single_title",5);
  44.  
  45. //remove related products
  46. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
  47.  
  48. //remove upsell products
  49. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15);
  50.  
  51. //remove single product imgages
  52. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
  53.  
  54. //remove single product thumbnails
  55. remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  56.  
  57. //remove before shop hooks
  58. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
  59. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
  60.  
  61. //remove after shop hooks
  62. remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
  63.  
  64. //category thumbnails
  65. remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
  66.  
  67. #-----------------------------------------
  68. #   add woo actions
  69. #-----------------------------------------
  70.  
  71. //wrapper adds
  72. add_action( 'woocommerce_before_main_content', 'rt_woocommerce_output_content_wrapper', 10);    // add new wrapper sub_page_header
  73. add_action( 'woocommerce_after_main_content', 'rt_woocommerce_output_content_wrapper_end', 10); // add new wrapper sub_page_footer
  74.  
  75. //paginatin
  76. add_action( 'woocommerce_pagination', 'rt_woocommerce_pagination', 10 ); // add new rt-pagination
  77.  
  78. //add custom thumbs
  79. add_action( 'woocommerce_before_shop_loop_item_title', 'rt_woocommerce_template_loop_product_thumbnail', 10);
  80.  
  81. //add related products
  82. add_action( 'woocommerce_after_single_product_summary', 'rt_woocommerce_output_related_products', 20);
  83.  
  84. // add title for single product title
  85. add_action( "woocommerce_before_single_product","rt_woocommerce_single_product_summary",5);
  86.  
  87. //add upsell products
  88. add_action( 'woocommerce_after_single_product_summary', 'rt_woocommerce_upsell_display', 15);
  89.  
  90. //remove single product imgages
  91. add_action( 'woocommerce_before_single_product_summary', 'rt_woocommerce_show_product_images', 20 );
  92.  
  93. //remove product thumbnails
  94. add_action( 'woocommerce_product_thumbnails', 'rt_woocommerce_show_product_thumbnails', 20 );
  95.  
  96. //category thumbnails
  97. add_action( 'woocommerce_before_subcategory_title', 'rt_woocommerce_subcategory_thumbnail', 10 );
  98.  
  99. #-----------------------------------------
  100. #   functions
  101. #-----------------------------------------
  102.  
  103. //removes woo style file
  104. function rt_remove_woo_stlyes(){
  105.     wp_deregister_style("woocommerce-general" );
  106.      
  107. }
  108.  
  109.  
  110. //wrapper sub page header
  111. function rt_woocommerce_output_content_wrapper(){
  112.     global $sidebar;
  113.  
  114.     //call sub page header
  115.     get_template_part( 'sub_page_header', 'sub_page_header_file' );
  116.  
  117.     //call the sub content holder 1st part
  118.     sub_page_layout("subheader",@$sidebar);
  119.    
  120.     echo '<div class="woocommerce">';
  121. }
  122.  
  123. //wrapper sub page header - end
  124. function rt_woocommerce_output_content_wrapper_end(){
  125.     global $sidebar;
  126.  
  127.     echo '</div><div class="space margin-b20"></div>';
  128.  
  129.     //call the sub content holder 2nd part
  130.     sub_page_layout("subfooter",@$sidebar);
  131. }
  132.  
  133.  
  134. //pagination
  135. function rt_woocommerce_pagination(){
  136.     echo '
  137.         <!-- paging-->
  138.         <div class="paging_wrapper clearfix">
  139.             <ul class="paging">
  140.         ';
  141.         get_pagination();
  142.  
  143.     echo '
  144.             </ul>
  145.         </div>
  146.     ';
  147. }
  148.  
  149. //thumbnail
  150. function rt_woocommerce_template_loop_product_thumbnail() {
  151.     global $post, $woocommerce, $placeholder_width, $placeholder_height, $title;
  152.    
  153.     $placeholder_width  = ! isset( $placeholder_width ) || empty( $placeholder_width ) ? $placeholder_width = wc_get_image_size( 'shop_catalog_image_width' ) : 1;
  154.     $placeholder_width  = is_array( $placeholder_width ) ? $placeholder_width["width"] : 1;
  155.    
  156.     $placeholder_height  = ! isset( $placeholder_height ) || empty( $placeholder_height ) ? $placeholder_height = wc_get_image_size( 'shop_catalog_image_height' ) : 1;
  157.     $placeholder_height  = is_array( $placeholder_height ) ? $placeholder_height["height"] : 1;
  158.  
  159.     $image = (has_post_thumbnail( $post->ID )) ? get_post_thumbnail_id($post->ID) : "";
  160.  
  161.     //Thumbnail dimensions
  162.     $w = ($placeholder_width > 640) ? 940 : (($placeholder_width > 400) ? 440 : 420);  
  163.     $h = get_option(THEMESLUG."_woo_product_image_height");
  164.  
  165.     // Crop
  166.     $crop = get_option(THEMESLUG."_woo_product_image_crop");
  167.     if($crop) $crop="true"; else $h=10000; 
  168.  
  169.     // Resize Image
  170.     if($image) $image_thumb = @vt_resize( $image, '',  $w, $h, ''.$crop.'' );
  171.  
  172.  
  173.     if ( has_post_thumbnail() )
  174.         echo    '<a href="'.get_permalink().'" class="imgeffect link"><img src="'.$image_thumb['url'].'"  alt="'. $title .'" /></a>';
  175.     else
  176.         echo '<a href="'.get_permalink().'" class="imgeffect link"><img src="'. woocommerce_placeholder_img_src() .'" alt="Placeholder" width="' . $placeholder_width . '" height="' . $placeholder_height . '" /></a>';
  177.  
  178.     echo '<div class="image-border-bottom"></div>';
  179. }
  180.  
  181. //Single Page Titles
  182. function rt_woocommerce_single_product_summary(){
  183.  
  184. echo '
  185.         <div class="box one box-shadow margin-b30">
  186.         <div class="head_text nomargin">
  187.             <div class="arrow"></div><!-- arrow -->
  188.         <h2>
  189. ';
  190.         if(is_page() || is_single()) the_title();
  191.  
  192.         if(is_tax())  echo single_term_title( "", false );
  193.  
  194.  
  195.     echo '
  196.         </h2>
  197.         </div>
  198.         </div>
  199.         <div class="clear"></div>
  200.     ';
  201. }
  202.  
  203. add_action( 'woocommerce_before_single_product_summary', 'rt_woocommerce_before_single_product_summary', 5);
  204. add_action( 'woocommerce_after_single_product_summary', 'rt_woocommerce_after_single_product_summary', 10);
  205.  
  206.  
  207. function rt_woocommerce_before_single_product_summary() {
  208.     echo '<div class="box one box-shadow margin-b30">';
  209. }
  210.  
  211. function rt_woocommerce_after_single_product_summary() {
  212.     echo "</div>";
  213. }
  214.  
  215. //Related Products
  216. function rt_woocommerce_output_related_products() {
  217.        
  218.         global $product, $woocommerce_loop,$related,$posts_per_page,$orderby,$columns;
  219.  
  220.         $woo_related_product_layout = get_option(THEMESLUG."_woo_related_product_list_pager");
  221.         $woo_related_product_layout = $woo_related_product_layout ? $woo_related_product_layout : 3; //default 3
  222.  
  223.         $related = $product->get_related();
  224.        
  225.         if ( sizeof($related) == 0 ) return;
  226.        
  227.         $args = apply_filters('woocommerce_related_products_args', array(
  228.             'post_type'         => 'product',
  229.             'ignore_sticky_posts'   => 1,
  230.             'no_found_rows'         => 1,
  231.             'posts_per_page'        => $woo_related_product_layout,
  232.             'orderby'           => $orderby,
  233.             'post__in'          => $related
  234.         ));
  235.        
  236.         $products = new WP_Query( $args );
  237.        
  238.         $woocommerce_loop['columns']    = $columns;
  239.        
  240.         if ( $products->have_posts() ) : ?>
  241.      
  242.         <div class="related products">
  243.             <div class="box one box-shadow margin-b30">
  244.                 <div class="head_text nomargin">
  245.                     <div class="arrow"></div><!-- arrow -->
  246.                     <h4><?php _e('Related Products', 'rt_theme'); ?></h4>
  247.                 </div>
  248.             </div>
  249.             <div class="clear"></div>
  250.                
  251.             <ul class="products">
  252.                
  253.                 <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  254.            
  255.                     <?php woocommerce_get_template_part( 'content', 'product' ); ?>
  256.        
  257.                 <?php endwhile; // end of the loop. ?>
  258.                    
  259.             </ul>
  260.            
  261.         </div>
  262.            
  263.         <?php endif;
  264.  
  265. }
  266.  
  267. //Up-Sells Products
  268. function rt_woocommerce_upsell_display() {
  269.        
  270.         global $product, $woocommerce_loop,$related,$posts_per_page,$orderby;
  271.        
  272.         $upsells = $product->get_upsells();
  273.        
  274.         if ( sizeof( $upsells ) == 0 ) return;
  275.        
  276.         $args = array(
  277.             'post_type'             => 'product',
  278.             'ignore_sticky_posts'   => 1,
  279.             'posts_per_page'        => 4,
  280.             'no_found_rows'         => 1,
  281.             'orderby'               => 'rand',
  282.             'post__in'              => $upsells
  283.         );
  284.        
  285.         $products = new WP_Query( $args );
  286.          
  287.         $woocommerce_loop['loop'] = 0;
  288.  
  289.         if ( $products->have_posts() ) : ?>
  290.      
  291.         <div class="related products">
  292.             <div class="box one box-shadow margin-b30">
  293.                 <div class="head_text nomargin">
  294.                     <div class="arrow"></div><!-- arrow -->
  295.                     <h4><?php _e('You may also like&hellip;', 'rt_theme'); ?></h4>
  296.                 </div>
  297.             </div>
  298.             <div class="clear"></div>
  299.                
  300.             <ul class="products">
  301.                
  302.                 <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  303.            
  304.                     <?php woocommerce_get_template_part( 'content', 'product' ); ?>
  305.        
  306.                 <?php endwhile; // end of the loop. ?>
  307.                    
  308.             </ul>
  309.            
  310.         </div>
  311.            
  312.         <?php endif;
  313.  
  314. }
  315.  
  316.  
  317. // Single Product Thumbnails
  318. function rt_woocommerce_show_product_images() {
  319. global $post, $woocommerce;
  320. ?>
  321.  
  322. <div class="single-product-images images">
  323.  
  324. <div class="product_single_featured_image box-shadow frame">
  325.     <?php if ( has_post_thumbnail() ) : ?>
  326.  
  327.         <a itemprop="image" href="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>"  class="imgeffect magnifier woocommerce-main-image zoom" data-gal="prettyPhoto[rt_theme_products]"  title="<?php echo get_the_title( get_post_thumbnail_id() ); ?>"><?php echo get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array("alt"=>esc_attr( $post->post_title)) ) ?></a>
  328.  
  329.     <?php else : ?>
  330.    
  331.         <img src="<?php echo woocommerce_placeholder_img_src(); ?>" alt="Placeholder" />
  332.    
  333.     <?php endif; ?>
  334. </div>
  335.     <?php do_action('woocommerce_product_thumbnails'); // call the thumbnails ?>
  336.  
  337. </div>
  338. <?php
  339. }
  340.  
  341. // Single Product Thumbnails
  342. function rt_woocommerce_show_product_thumbnails() {
  343.  
  344. global $post, $product, $woocommerce;
  345.  
  346.    
  347.     $attachment_ids = $product->get_gallery_attachment_ids();
  348.  
  349.     if ( $attachment_ids ) {
  350.  
  351.         $loop = 0;
  352.         $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
  353.  
  354.         $imagesHTML = "";
  355.         foreach ( $attachment_ids as $attachment_id ) {
  356.  
  357.             $classes = array( 'zoom' );
  358.  
  359.             if ( $loop == 0 || $loop % $columns == 0 )
  360.                 $classes[] = 'first';
  361.  
  362.             if ( ( $loop + 1 ) % $columns == 0 )
  363.                 $classes[] = 'last';
  364.  
  365.             $image_link = wp_get_attachment_url( $attachment_id );
  366.  
  367.             if ( ! $image_link )
  368.                 continue;
  369.  
  370.             $image_title = esc_attr( get_the_title( $attachment_id ) );
  371.  
  372.             //resize the photo
  373.             $w = 110;
  374.             $h = 90;
  375.             $crop = "true";
  376.             $image_thumb = @vt_resize('' , $image_link, $w, $h, $crop );     
  377.  
  378.             $imagesHTML .=  '<li><a class="imgeffect magnifier" href="'.wp_get_attachment_url( $attachment_id ).'" data-gal="prettyPhoto[rt_theme_products]" title="'. $image_title .'"><img src="'.$image_thumb['url'].'" width="'.$image_thumb['width'].'" alt="'. $image_title .'" /></a></li>';
  379.  
  380.         }
  381.     }
  382.  
  383.     if(trim(isset($imagesHTML))){
  384.         echo '<div class="carousel box-shadow margin-t20 woo-product-thumbs">';
  385.         echo '<ul id="product_thumbnails" class="jcarousel-skin-rt">';
  386.         echo $imagesHTML;
  387.         echo '</ul></div>';
  388.     }
  389.  
  390. }
  391.  
  392. //category thumbnails
  393. function rt_woocommerce_subcategory_thumbnail( $category ) {
  394.     global $woocommerce;
  395.  
  396.     $small_thumbnail_size   = apply_filters( 'single_product_small_thumbnail_size', 'shop_catalog' );
  397.     $dimensions             = wc_get_image_size( $small_thumbnail_size );
  398.     $thumbnail_id           = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true  );
  399.  
  400.     if ( $thumbnail_id ) {
  401.         $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size  );
  402.         $image = $image[0];
  403.     } else {
  404.         $image = woocommerce_placeholder_img_src();
  405.     }
  406.  
  407.     if ( $image )
  408.         echo '<a href="'.get_term_link( $category->slug, 'product_cat' ).'">';
  409.         echo '<img src="' . $image . '" alt="' . $category->name . '" width="' . $dimensions['width'] . '" height="' . $dimensions['height'] . '" />';
  410.         echo "</a>";
  411. }
  412.  
  413.  
  414. #-----------------------------------------
  415. #   RT - WOOCOMMERCE Options
  416. #-----------------------------------------
  417. global $woo_product_layout, $woo_layout_names, $woo_column_class_name;
  418.  
  419.  
  420. #
  421. # COLUMN LAYOUT
  422. #
  423.  
  424. $woo_product_layout = get_option(THEMESLUG."_woo_product_layout");
  425. $woo_product_layout = $woo_product_layout ? $woo_product_layout : 3; //default 3
  426.  
  427. // woo layouts
  428. $woo_layout_names = array("5"=>"five","4"=>"four","3"=>"three","2"=>"two","1"=>"one");
  429. $woo_column_class_name = $woo_layout_names[$woo_product_layout];
  430.  
  431. // Change number or products per row to 3
  432. add_filter('loop_shop_columns', 'loop_columns');
  433. if (!function_exists('loop_columns')) {
  434.     function loop_columns() {
  435.         global $woo_product_layout;
  436.         return $woo_product_layout;
  437.     }
  438. }
  439.  
  440. // add column value as javascript value to header
  441. add_filter('wp_head', 'rt_woo_column_jquery_var');
  442. if (!function_exists('rt_woo_column_jquery_var')) {
  443.     function rt_woo_column_jquery_var() {
  444.     global $woo_product_layout;
  445.             $output = "\n";
  446.             $output .= '<script type="text/javascript">'."\n";
  447.             $output .= '//<![CDATA['."\n";       
  448.             $output .= 'var woo_product_layout=\''.$woo_product_layout.'\';'."\n";           
  449.             $output .= '//]]>'."\n";
  450.             $output .= '</script>'."\n";
  451.            
  452.         echo $output;
  453.     }
  454. }
  455. ;
  456.  
  457. #
  458. # Number of products displayed per page
  459. #
  460. $woo_product_list_pager = get_option(THEMESLUG."_woo_product_list_pager");
  461. if($woo_product_list_pager!="" && is_numeric($woo_product_list_pager) ) add_filter('loop_shop_per_page', create_function('$cols', 'return '.$woo_product_list_pager.';'));
  462.  
  463.  
  464. #
  465. # Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
  466. #
  467. add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
  468. function woocommerce_header_add_to_cart_fragment( $fragments ) {
  469.     global $woocommerce;
  470.     ob_start();
  471.     ?>
  472.     <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'rt_theme'); ?>">
  473.  
  474.         <?php
  475.         if($woocommerce->cart->cart_contents_count > 1 )
  476.             echo sprintf(__('%d items', 'rt_theme'), $woocommerce->cart->cart_contents_count);
  477.         else
  478.             echo sprintf(__('%d item', 'rt_theme'), $woocommerce->cart->cart_contents_count);
  479.         ?>
  480.         - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
  481.     <?php
  482.     $fragments['a.cart-contents'] = ob_get_clean();
  483.     return $fragments;
  484. }
  485.  
  486. ?>