RtThemesSupport

woo-integration.php rt17

Mar 21st, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.22 KB | None | 0 0
  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' ) : $placeholder_width;
  154.  
  155.     $placeholder_width  = is_array( $placeholder_width ) ? $placeholder_width["width"] : $placeholder_width;
  156.  
  157.     $placeholder_height  = (! isset( $placeholder_height ) || empty( $placeholder_height )) ? $placeholder_height = wc_get_image_size( 'shop_catalog_image_height' ) : $placeholder_height;
  158.     $placeholder_height  = is_array( $placeholder_height ) ? $placeholder_height["height"] : $placeholder_height;
  159.    
  160.     $image = (has_post_thumbnail( $post->ID )) ? get_post_thumbnail_id($post->ID) : "";
  161.  
  162.     //Thumbnail dimensions
  163.     $w = ($placeholder_width > 640) ? 940 : (($placeholder_width > 400) ? 440 : 420);  
  164.     $h = get_option(THEMESLUG."_woo_product_image_height");
  165.  
  166.     // Crop
  167.     $crop = get_option(THEMESLUG."_woo_product_image_crop");
  168.     if ($crop) $w=$h;
  169.     if($crop) $crop="true"; else $h=10000; 
  170.  
  171.     // Resize Image
  172.     if($image) $image_thumb = @vt_resize( $image, '',  $w, $h, ''.$crop.'' );
  173.  
  174.  
  175.     if ( has_post_thumbnail() )
  176.         echo    '<a href="'.get_permalink().'" class="imgeffect link"><img src="'.$image_thumb['url'].'"  alt="'. $title .'" /></a>';
  177.     else
  178.         echo '<a href="'.get_permalink().'" class="imgeffect link"><img src="'. woocommerce_placeholder_img_src() .'" alt="Placeholder" width="' . $placeholder_width . '" height="' . get_option(THEMESLUG."_woo_product_image_height") . '" /></a>';
  179.  
  180.     echo '<div class="image-border-bottom"></div>';
  181. }
  182.  
  183. //Single Page Titles
  184. function rt_woocommerce_single_product_summary(){
  185.  
  186. echo '
  187.         <div class="box one box-shadow margin-b30">
  188.         <div class="head_text nomargin">
  189.             <div class="arrow"></div><!-- arrow -->
  190.         <h2>
  191. ';
  192.         if(is_page() || is_single()) the_title();
  193.  
  194.         if(is_tax())  echo single_term_title( "", false );
  195.  
  196.  
  197.     echo '
  198.         </h2>
  199.         </div>
  200.         </div>
  201.         <div class="clear"></div>
  202.     ';
  203. }
  204.  
  205. add_action( 'woocommerce_before_single_product_summary', 'rt_woocommerce_before_single_product_summary', 5);
  206. add_action( 'woocommerce_after_single_product_summary', 'rt_woocommerce_after_single_product_summary', 10);
  207.  
  208.  
  209. function rt_woocommerce_before_single_product_summary() {
  210.     echo '<div class="box one box-shadow margin-b30">';
  211. }
  212.  
  213. function rt_woocommerce_after_single_product_summary() {
  214.     echo "</div>";
  215. }
  216.  
  217. //Related Products
  218. function rt_woocommerce_output_related_products() {
  219.        
  220.         global $product, $woocommerce_loop,$related,$posts_per_page,$orderby,$columns;
  221.  
  222.         $woo_related_product_layout = get_option(THEMESLUG."_woo_related_product_list_pager");
  223.         $woo_related_product_layout = $woo_related_product_layout ? $woo_related_product_layout : 3; //default 3
  224.  
  225.         $related = $product->get_related();
  226.        
  227.         if ( sizeof($related) == 0 ) return;
  228.        
  229.         $args = apply_filters('woocommerce_related_products_args', array(
  230.             'post_type'         => 'product',
  231.             'ignore_sticky_posts'   => 1,
  232.             'no_found_rows'         => 1,
  233.             'posts_per_page'        => $woo_related_product_layout,
  234.             'orderby'           => $orderby,
  235.             'post__in'          => $related
  236.         ));
  237.        
  238.         $products = new WP_Query( $args );
  239.        
  240.         $woocommerce_loop['columns']    = $columns;
  241.        
  242.         if ( $products->have_posts() ) : ?>
  243.      
  244.         <div class="related products">
  245.             <div class="box one box-shadow margin-b30">
  246.                 <div class="head_text nomargin">
  247.                     <div class="arrow"></div><!-- arrow -->
  248.                     <h4><?php _e('Related Products', 'rt_theme'); ?></h4>
  249.                 </div>
  250.             </div>
  251.             <div class="clear"></div>
  252.                
  253.             <ul class="products">
  254.                
  255.                 <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  256.            
  257.                     <?php woocommerce_get_template_part( 'content', 'product' ); ?>
  258.        
  259.                 <?php endwhile; // end of the loop. ?>
  260.                    
  261.             </ul>
  262.            
  263.         </div>
  264.            
  265.         <?php endif;
  266.  
  267. }
  268.  
  269. //Up-Sells Products
  270. function rt_woocommerce_upsell_display() {
  271.        
  272.         global $product, $woocommerce_loop,$related,$posts_per_page,$orderby;
  273.        
  274.         $upsells = $product->get_upsells();
  275.        
  276.         if ( sizeof( $upsells ) == 0 ) return;
  277.        
  278.         $args = array(
  279.             'post_type'             => 'product',
  280.             'ignore_sticky_posts'   => 1,
  281.             'posts_per_page'        => 4,
  282.             'no_found_rows'         => 1,
  283.             'orderby'               => 'rand',
  284.             'post__in'              => $upsells
  285.         );
  286.        
  287.         $products = new WP_Query( $args );
  288.          
  289.         $woocommerce_loop['loop'] = 0;
  290.  
  291.         if ( $products->have_posts() ) : ?>
  292.      
  293.         <div class="related products">
  294.             <div class="box one box-shadow margin-b30">
  295.                 <div class="head_text nomargin">
  296.                     <div class="arrow"></div><!-- arrow -->
  297.                     <h4><?php _e('You may also like&hellip;', 'rt_theme'); ?></h4>
  298.                 </div>
  299.             </div>
  300.             <div class="clear"></div>
  301.                
  302.             <ul class="products">
  303.                
  304.                 <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  305.            
  306.                     <?php woocommerce_get_template_part( 'content', 'product' ); ?>
  307.        
  308.                 <?php endwhile; // end of the loop. ?>
  309.                    
  310.             </ul>
  311.            
  312.         </div>
  313.            
  314.         <?php endif;
  315.  
  316. }
  317.  
  318.  
  319. // Single Product Thumbnails
  320. function rt_woocommerce_show_product_images() {
  321. global $post, $woocommerce;
  322. ?>
  323.  
  324. <div class="single-product-images images">
  325.  
  326. <div class="product_single_featured_image box-shadow frame">
  327.     <?php if ( has_post_thumbnail() ) : ?>
  328.  
  329.         <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>
  330.  
  331.     <?php else : ?>
  332.    
  333.         <img src="<?php echo woocommerce_placeholder_img_src(); ?>" alt="Placeholder" />
  334.    
  335.     <?php endif; ?>
  336. </div>
  337.     <?php do_action('woocommerce_product_thumbnails'); // call the thumbnails ?>
  338.  
  339. </div>
  340. <?php
  341. }
  342.  
  343. // Single Product Thumbnails
  344. function rt_woocommerce_show_product_thumbnails() {
  345.  
  346. global $post, $product, $woocommerce;
  347.  
  348.    
  349.     $attachment_ids = $product->get_gallery_attachment_ids();
  350.  
  351.     if ( $attachment_ids ) {
  352.  
  353.         $loop = 0;
  354.         $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
  355.  
  356.         $imagesHTML = "";
  357.         foreach ( $attachment_ids as $attachment_id ) {
  358.  
  359.             $classes = array( 'zoom' );
  360.  
  361.             if ( $loop == 0 || $loop % $columns == 0 )
  362.                 $classes[] = 'first';
  363.  
  364.             if ( ( $loop + 1 ) % $columns == 0 )
  365.                 $classes[] = 'last';
  366.  
  367.             $image_link = wp_get_attachment_url( $attachment_id );
  368.  
  369.             if ( ! $image_link )
  370.                 continue;
  371.  
  372.             $image_title = esc_attr( get_the_title( $attachment_id ) );
  373.  
  374.             //resize the photo
  375.             $w = 110;
  376.             $h = 90;
  377.             $crop = "true";
  378.             $image_thumb = @vt_resize('' , $image_link, $w, $h, $crop );     
  379.  
  380.             $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>';
  381.  
  382.         }
  383.     }
  384.  
  385.     if(trim(isset($imagesHTML))){
  386.         echo '<div class="carousel box-shadow margin-t20 woo-product-thumbs">';
  387.         echo '<ul id="product_thumbnails" class="jcarousel-skin-rt">';
  388.         echo $imagesHTML;
  389.         echo '</ul></div>';
  390.     }
  391.  
  392. }
  393.  
  394. //category thumbnails
  395. function rt_woocommerce_subcategory_thumbnail( $category ) {
  396.     global $woocommerce;
  397.  
  398.     $small_thumbnail_size   = apply_filters( 'single_product_small_thumbnail_size', 'shop_catalog' );
  399.     $dimensions             = wc_get_image_size( $small_thumbnail_size );
  400.     $thumbnail_id           = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true  );
  401.  
  402.     if ( $thumbnail_id ) {
  403.         $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size  );
  404.         $image = $image[0];
  405.     } else {
  406.         $image = woocommerce_placeholder_img_src();
  407.     }
  408.  
  409.     if ( $image ) {
  410.         echo '<a href="'.get_term_link( $category->slug, 'product_cat' ).'">';
  411.         echo '<img src="' . $image . '" alt="' . $category->name . '" width="' . $dimensions['width'] . '" height="' . $dimensions['height'] . '" />';
  412.         echo "</a>";
  413.     }
  414. }
  415.  
  416.  
  417. #-----------------------------------------
  418. #   RT - WOOCOMMERCE Options
  419. #-----------------------------------------
  420. global $woo_product_layout, $woo_layout_names, $woo_column_class_name;
  421.  
  422.  
  423. #
  424. # COLUMN LAYOUT
  425. #
  426.  
  427. $woo_product_layout = get_option(THEMESLUG."_woo_product_layout");
  428. $woo_product_layout = $woo_product_layout ? $woo_product_layout : 3; //default 3
  429.  
  430. // woo layouts
  431. $woo_layout_names = array("5"=>"five","4"=>"four","3"=>"three","2"=>"two","1"=>"one");
  432. $woo_column_class_name = $woo_layout_names[$woo_product_layout];
  433.  
  434. // Change number or products per row to 3
  435. add_filter('loop_shop_columns', 'loop_columns');
  436. if (!function_exists('loop_columns')) {
  437.     function loop_columns() {
  438.         global $woo_product_layout;
  439.         return $woo_product_layout;
  440.     }
  441. }
  442.  
  443. // add column value as javascript value to header
  444. add_filter('wp_head', 'rt_woo_column_jquery_var');
  445. if (!function_exists('rt_woo_column_jquery_var')) {
  446.     function rt_woo_column_jquery_var() {
  447.     global $woo_product_layout;
  448.             $output = "\n";
  449.             $output .= '<script type="text/javascript">'."\n";
  450.             $output .= '//<![CDATA['."\n";       
  451.             $output .= 'var woo_product_layout=\''.$woo_product_layout.'\';'."\n";           
  452.             $output .= '//]]>'."\n";
  453.             $output .= '</script>'."\n";
  454.            
  455.         echo $output;
  456.     }
  457. }
  458. ;
  459.  
  460. #
  461. # Number of products displayed per page
  462. #
  463. $woo_product_list_pager = get_option(THEMESLUG."_woo_product_list_pager");
  464. 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.';'));
  465.  
  466.  
  467. #
  468. # Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
  469. #
  470. add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
  471. function woocommerce_header_add_to_cart_fragment( $fragments ) {
  472.     global $woocommerce;
  473.     ob_start();
  474.     ?>
  475.     <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'rt_theme'); ?>">
  476.  
  477.         <?php
  478.         if($woocommerce->cart->cart_contents_count > 1 )
  479.             echo sprintf(__('%d items', 'rt_theme'), $woocommerce->cart->cart_contents_count);
  480.         else
  481.             echo sprintf(__('%d item', 'rt_theme'), $woocommerce->cart->cart_contents_count);
  482.         ?>
  483.         - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
  484.     <?php
  485.     $fragments['a.cart-contents'] = ob_get_clean();
  486.     return $fragments;
  487. }
  488.  
  489. ?>
Advertisement
Add Comment
Please, Sign In to add comment