Advertisement
Guest User

Untitled

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