Advertisement
Guest User

woo-integration.php

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