Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.90 KB | None | 0 0
  1. <?php
  2. /**
  3. * All functions and hooks for jigoshop plugin
  4. *
  5. * @package WordPress
  6. * @subpackage YIW Themes
  7. * @since 1.4
  8. */
  9.  
  10. // global flag to know that woocommerce is active
  11. $yiw_is_woocommerce = true;
  12.  
  13. include 'shortcodes-woocommerce.php';
  14.  
  15. remove_action( 'woocommerce_pagination', 'woocommerce_catalog_ordering', 20 );
  16. add_action( 'woocommerce_before_main_content' , create_function( '', 'if ( ! is_single() ) woocommerce_catalog_ordering();' ) );
  17.  
  18. // add the sale icon inside the product detail image container
  19. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10);
  20. add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_sale_flash');
  21.  
  22. // active the price filter /**
  23. /**add_action('init', 'woocommerce_price_filter_init');
  24. add_filter('loop_shop_post_in', 'woocommerce_price_filter'); */
  25.  
  26. // add body class
  27. add_filter( 'body_class', create_function( '$classes', '$classes[] = "shop-".yiw_get_option( "shop_products_style", "ribbon" ); return $classes;' ) );
  28.  
  29. // remove the add to cart option
  30. function yiw_remove_add_to_cart() {
  31. if ( yiw_get_option('shop_show_button_add_to_cart_single_page') ) return;
  32. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
  33. }
  34. add_action('init', 'yiw_remove_add_to_cart');
  35.  
  36. // since woocommerce 1.6 - add the style to <ul> products list
  37. function yiw_add_style_products_list( $content ) {
  38. return str_replace( '<ul class="products">', '<ul class="products ' . yiw_get_option( 'shop_products_style', 'ribbon' ) . '">', $content );
  39. }
  40. add_filter( 'the_content', 'yiw_add_style_products_list', 99 );
  41.  
  42. // add image size for the product categories in woocommerce api
  43. add_filter( 'woocommerce_get_image_size_shop_category_image_width', create_function( '', 'return get_option("woocommerce_category_image_width");' ) );
  44. add_filter( 'woocommerce_get_image_size_shop_category_image_height', create_function( '', 'return get_option("woocommerce_category_image_height");' ) );
  45.  
  46. function yiw_set_posts_per_page( $cols ) {
  47. $items = yiw_get_option( 'shop_products_per_page', $cols );
  48. return $items == 0 ? -1 : $items;
  49. }
  50. add_filter('loop_shop_per_page', 'yiw_set_posts_per_page');
  51.  
  52. function yiw_add_style_woocommerce() {
  53. wp_enqueue_style( 'jquery-ui-style', (is_ssl()) ? 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' : 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
  54. }
  55. add_action( 'init', 'yiw_add_style_woocommerce' );
  56.  
  57. function yiw_add_to_cart_success_ajax( $datas ) {
  58. global $woocommerce;
  59.  
  60. // quantity
  61. $qty = 0;
  62. if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
  63.  
  64. $qty += $values['quantity'];
  65.  
  66. endforeach; endif;
  67.  
  68. if ( $qty == 1 )
  69. $label = __( 'item', 'yiw' );
  70. else
  71. $label = __( 'items', 'yiw' );
  72.  
  73. ob_start();
  74. echo '<ul class="cart_list product_list_widget hide_cart_widget_if_empty">';
  75. if (sizeof($woocommerce->cart->get_cart())>0) :
  76. foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) :
  77. $_product = $cart_item['data'];
  78. if ($_product->exists() && $cart_item['quantity']>0) :
  79. echo '<li><a href="'.get_permalink($cart_item['product_id']).'">';
  80.  
  81. echo $_product->get_image();
  82.  
  83. echo apply_filters('woocommerce_cart_widget_product_title', $_product->get_title(), $_product).'</a>';
  84.  
  85. echo $woocommerce->cart->get_item_data( $cart_item );
  86.  
  87. echo '<span class="quantity">' .$cart_item['quantity'].' &times; '.woocommerce_price($_product->get_price()).'</span></li>';
  88. endif;
  89. endforeach;
  90. else:
  91. echo '<li class="empty">'.__('No products in the cart.', 'woocommerce').'</li>';
  92. endif;
  93. echo '</ul>';
  94. if ($qty == 1) :
  95. echo '<p class="total"><strong>' . __('Subtotal', 'woocommerce') . ':</strong> '. $woocommerce->cart->get_cart_total() . '</p>';
  96.  
  97. do_action( 'woocommerce_widget_shopping_cart_before_buttons' );
  98.  
  99. echo '<p class="buttons"><a href="'.$woocommerce->cart->get_cart_url().'" class="button">'.__('View Cart &rarr;', 'woocommerce').'</a> <a href="'.$woocommerce->cart->get_checkout_url().'" class="button checkout">'.__('Checkout &rarr;', 'woocommerce').'</a></p>';
  100. endif;
  101. $widget = ob_get_clean();
  102.  
  103. //$datas['span.minicart'] = '<span class="minicart">' . $qty . ' ' . $label . '</span>';
  104. $datas['.widget_shopping_cart .product_list_widget'] = $widget;
  105. $datas['.widget_shopping_cart .total .amount'] = $woocommerce->cart->get_cart_total();
  106. $datas['#cart'] = '<div id="cart">' . yiw_minicart(false) . '</div>';
  107.  
  108. return $datas;
  109. }
  110. add_filter( 'add_to_cart_fragments', 'yiw_add_to_cart_success_ajax' );
  111.  
  112. function yiw_woocommerce_javascript_scripts() {
  113. ?>
  114. <script type="text/javascript">
  115. jQuery(document).ready(function($){
  116. $('body').bind('added_to_cart', function(){
  117. $('.add_to_cart_button.added').text('ADDED');
  118. });
  119. });
  120. </script>
  121. <?php
  122. }
  123. add_action( 'wp_head', 'yiw_woocommerce_javascript_scripts' );
  124.  
  125.  
  126. /** SHOP
  127. -------------------------------------------------------------------- */
  128.  
  129. // decide the layout for the shop pages
  130. function yiw_shop_layouts( $default_layout ) {
  131. $is_shop_page = ( get_option('woocommerce_shop_page_id') != false ) ? is_page( get_option('woocommerce_shop_page_id') ) : false;
  132. if ( is_tax('product_cat') || is_post_type_archive('product') || $is_shop_page )
  133. return YIW_DEFAULT_LAYOUT_PAGE_SHOP;
  134. else
  135. return $default_layout;
  136. }
  137. add_filter( 'yiw_layout_page', 'yiw_shop_layouts' );
  138.  
  139. // generate the main width for content and sidebar
  140. function yiw_layout_widths() {
  141. global $content_width, $post;
  142.  
  143. $sidebar = YIW_SIDEBAR_WIDTH;
  144.  
  145. $post_id = isset( $post->ID ) ? $post->ID : 0;
  146.  
  147. if ( ! is_search() && get_post_type() == 'product' || get_post_meta( $post_id, '_sidebar_choose_page', true ) == 'Shop Sidebar' )
  148. $sidebar = YIW_SIDEBAR_SHOP_WIDTH;
  149.  
  150. $content_width = YIW_MAIN_WIDTH - ( $sidebar + 40 );
  151.  
  152. ?>
  153. #content { width:<?php echo $content_width ?>px; }
  154. #sidebar { width:<?php echo $sidebar ?>px; }
  155. #sidebar.shop { width:<?php echo YIW_SIDEBAR_SHOP_WIDTH ?>px; }
  156. <?php
  157. }
  158. //add_action( 'yiw_custom_styles', 'yiw_layout_widths' );
  159.  
  160. function yiw_minicart( $echo = true ) {
  161. global $woocommerce;
  162.  
  163. ob_start();
  164.  
  165. // quantity
  166. $qty = 0;
  167. if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
  168.  
  169. $qty += $values['quantity'];
  170.  
  171. endforeach; endif;
  172.  
  173. if ( $qty == 1 )
  174. $label = __( 'item', 'yiw' );
  175. else
  176. $label = __( 'items', 'yiw' ); ?>
  177.  
  178. <a class="widget_shopping_cart trigger" href="<?php echo $woocommerce->cart->get_cart_url() ?>">
  179. <span class="minicart"><?php echo $qty ?> <?php echo $label ?> </span>
  180. </a>
  181.  
  182. <?php if ( yiw_get_option('topbar_cart_ribbon_hover') ) : ?>
  183. <div class="quick-cart">
  184. <ul class="cart_list product_list_widget"><?php
  185.  
  186. if (sizeof($woocommerce->cart->get_cart())>0) :
  187. foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) :
  188. $_product = $cart_item['data'];
  189. if ($_product->exists() && $cart_item['quantity']>0) : ?>
  190. <li>
  191. <a href="<?php echo get_permalink($cart_item['product_id']) ?>"><?php echo apply_filters('woocommerce_cart_widget_product_title', $_product->get_title(), $_product) ?></a>
  192. <span class="price"><?php echo woocommerce_price($_product->get_price()); ?></span>
  193. </li><?php
  194. endif;
  195. endforeach;
  196. else : ?>
  197. <li class="empty"><?php _e('Geen producten in winkelwagen.', 'woocommerce') ?></li><?php
  198. endif;
  199.  
  200. if (sizeof($woocommerce->cart->get_cart())>0) : ?>
  201. <li class="totals"><?php _e( 'Subtotaal', 'yiw' ) ?><span class="price"><?php echo $woocommerce->cart->get_cart_total(); ?></span></li><?php
  202. endif; ?>
  203.  
  204. <li class="view-cart-button"><a class="view-cart-button" href="<?php echo get_permalink( get_option('woocommerce_cart_page_id') ); ?>"><?php _e( apply_filters( 'yiw_topbar_minicart_view_cart', 'Winkelwagen' ), 'yiw' ) ?></a></li>
  205.  
  206. </ul>
  207.  
  208. </div><?php
  209. endif;
  210.  
  211. $html = ob_get_clean();
  212.  
  213. if ( $echo )
  214. echo $html;
  215. else
  216. return $html;
  217. }
  218.  
  219. // Decide if show the price and/or the button add to cart, on the product detail page
  220. function yiw_remove_ecommerce() {
  221. if ( ! yiw_get_option( 'shop_show_button_add_to_cart_single_page', 1 ) )
  222. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  223. if ( ! yiw_get_option( 'shop_show_price_single_page', 1 ) )
  224. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
  225. }
  226. add_action( 'wp_head', 'yiw_remove_ecommerce', 1 );
  227.  
  228. /**
  229. * LAYOUT
  230. */
  231. function yiw_shop_layout_pages_before() {
  232. $layout = yiw_layout_page();
  233. if ( get_post_type() == 'product' && is_tax( 'product-category' ) )
  234. $layout = 'sidebar-no';
  235. elseif ( get_post_type() == 'product' && is_single() )
  236. $layout = yiw_get_option( 'shop_layout_page_single', 'sidebar-no' );
  237. elseif ( get_post_type() == 'product' && ! is_single() )
  238. $layout = ( $l=get_post_meta( get_option( 'woocommerce_shop_page_id' ), '_layout_page', true )) ? $l : YIW_DEFAULT_LAYOUT_PAGE;
  239. ?><div id="primary" class="layout-<?php echo $layout ?> group">
  240. <div class="inner group"><?php
  241.  
  242. if ( $layout == 'sidebar-no' ) {
  243. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
  244. add_filter('loop_shop_columns', create_function('$columns', 'return $columns+1;'));
  245. }
  246. }
  247.  
  248. function yiw_shop_layout_pages_after() {
  249. ?></div></div><?php
  250. }
  251.  
  252. add_action( 'woocommerce_before_main_content', 'yiw_shop_layout_pages_before', 1 );
  253. add_action( 'woocommerce_sidebar', 'yiw_shop_layout_pages_after', 99 );
  254.  
  255. /**
  256. * SIZES
  257. */
  258.  
  259. // shop small
  260. function yiw_shop_small_w() { global $woocommerce; return $woocommerce->get_image_size('shop_catalog_image_width'); }
  261. function yiw_shop_small_h() { global $woocommerce; return $woocommerce->get_image_size('shop_catalog_image_height'); }
  262. // shop thumbnail
  263. function yiw_shop_thumbnail_w() { global $woocommerce; return $woocommerce->get_image_size('shop_thumbnail_image_width'); }
  264. function yiw_shop_thumbnail_h() { global $woocommerce; return $woocommerce->get_image_size('shop_thumbnail_image_height'); }
  265. // shop large
  266. function yiw_shop_large_w() { global $woocommerce; return $woocommerce->get_image_size('shop_single_image_width'); }
  267. function yiw_shop_large_h() { global $woocommerce; return $woocommerce->get_image_size('shop_single_image_height'); }
  268. // category image
  269. function yiw_shop_category_w() { global $woocommerce; return $woocommerce->get_image_size('shop_category_image_width'); }
  270. function yiw_shop_category_h() { global $woocommerce; return $woocommerce->get_image_size('shop_category_image_height'); }
  271.  
  272. /**
  273. * Init images
  274. */
  275. function yiw_image_sizes() {
  276. global $woocommerce;
  277.  
  278. // Image sizes
  279. $shop_category_crop = (get_option('woocommerce_category_image_crop')==1) ? true : false;
  280.  
  281. add_image_size( 'shop_category', $woocommerce->get_image_size('shop_category_image_width'), $woocommerce->get_image_size('shop_category_image_height'), $shop_category_crop );
  282. }
  283. add_action( 'woocommerce_init', 'yiw_image_sizes' );
  284.  
  285. // print style for small thumb size
  286. function yiw_size_images_style() {
  287. ?>
  288. .shop-traditional .products li { width:<?php echo yiw_shop_small_w() + ( yiw_get_option( 'shop_border_thumbnail' ) ? 14 : 0 ) ?>px !important; }
  289. .shop-ribbon .products li { width:<?php echo yiw_shop_small_w() + 5 ?>px !important; }
  290. .shop-ribbon .products li.category { width: auto !important; }
  291. .products li a strong { width:<?php echo yiw_shop_small_w() - 30 ?>px !important; }
  292. /*..shop-traditional .products li a img { width:<?php echo yiw_shop_small_w() ?>px !important; } removed for the category images */
  293. div.product div.images { width:<?php echo ( yiw_shop_large_w() + 14 ) / 720 * 100 ?>%; }
  294. .layout-sidebar-no div.product div.images { width:<?php echo ( yiw_shop_large_w() + 14 ) / 960 * 100 ?>%; }
  295. div.product div.images img { width:<?php echo yiw_shop_large_w() ?>px; }
  296. .layout-sidebar-no div.product div.summary { width:<?php echo ( 960 - ( yiw_shop_large_w() + 14 ) - 20 ) / 960 * 100 ?>%; }
  297. .layout-sidebar-right div.product div.summary, .layout-sidebar-left div.product div.summary { width:<?php echo ( 720 - ( yiw_shop_large_w() + 14 ) - 20 ) / 720 * 100 ?>%; }
  298. .layout-sidebar-no .product.hentry > span.onsale { right:<?php echo 960 - ( yiw_shop_large_w() + 14 ) - 10 ?>px; left:auto; }
  299. .layout-sidebar-right .product.hentry > span.onsale, .layout-sidebar-left .product.hentry > span.onsale { right:<?php echo 720 - ( yiw_shop_large_w() + 14 ) - 10 ?>px; left:auto; }
  300. <?php
  301. }
  302. add_action( 'yiw_custom_styles', 'yiw_size_images_style' );
  303.  
  304. /**
  305. * PRODUCT PAGE
  306. */
  307. add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
  308. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10);
  309. add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 60);
  310.  
  311. function woocommerce_output_related_products() {
  312. echo '<div id="related-products">';
  313. echo '<h3>', __( 'Related Products', 'yiw' ), '</h3>';
  314. $cols = yiw_layout_page() == 'sidebar-no' ? 5 : 4;
  315. woocommerce_related_products( apply_filters('related_products_posts_per_page', $cols), apply_filters('related_products_columns', $cols) );
  316. echo '</div>';
  317. }
  318.  
  319. // number of products
  320. function yiw_items_list_pruducts() {
  321. return 8;
  322. }
  323. //add_filter( 'loop_shop_per_page', 'yiw_items_list_pruducts' );
  324.  
  325.  
  326.  
  327. /** NAV MENU
  328. -------------------------------------------------------------------- */
  329.  
  330. add_action('admin_init', array('yiwProductsPricesFilter', 'admin_init'));
  331.  
  332. class yiwProductsPricesFilter {
  333. // We cannot call #add_meta_box yet as it has not been defined,
  334. // therefore we will call it in the admin_init hook
  335. function admin_init() {
  336. if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) || basename($_SERVER['PHP_SELF']) != 'nav-menus.php' )
  337. return;
  338.  
  339. wp_enqueue_script('nav-menu-query', get_template_directory_uri() . '/inc/admin_scripts/metabox_nav_menu.js', 'nav-menu', false, true);
  340. add_meta_box('products-by-prices', 'Prices Filter', array(__CLASS__, 'nav_menu_meta_box'), 'nav-menus', 'side', 'low');
  341. }
  342.  
  343. function nav_menu_meta_box() { ?>
  344. <div class="prices">
  345. <input type="hidden" name="woocommerce_currency" id="woocommerce_currency" value="<?php echo get_woocommerce_currency_symbol( get_option('woocommerce_currency') ) ?>" />
  346. <input type="hidden" name="woocommerce_shop_url" id="woocommerce_shop_url" value="<?php echo get_option('permalink_structure') == '' ? site_url() . '/?post_type=product' : get_permalink( get_option('woocommerce_shop_page_id') ) ?>" />
  347. <input type="hidden" name="menu-item[-1][menu-item-url]" value="" />
  348. <input type="hidden" name="menu-item[-1][menu-item-title]" value="" />
  349. <input type="hidden" name="menu-item[-1][menu-item-type]" value="custom" />
  350.  
  351. <p>
  352. <?php _e( sprintf( 'The values are already expressed in %s', get_woocommerce_currency_symbol( get_option('woocommerce_currency') ) ), 'yiw' ) ?>
  353. </p>
  354.  
  355. <p>
  356. <label class="howto" for="prices_filter_from">
  357. <span><?php _e('From'); ?></span>
  358. <input id="prices_filter_from" name="prices_filter_from" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('From'); ?>" />
  359. </label>
  360. </p>
  361.  
  362. <p style="display: block; margin: 1em 0; clear: both;">
  363. <label class="howto" for="prices_filter_to">
  364. <span><?php _e('To'); ?></span>
  365. <input id="prices_filter_to" name="prices_filter_to" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('To'); ?>" />
  366. </label>
  367. </p>
  368.  
  369. <p class="button-controls">
  370. <span class="add-to-menu">
  371. <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  372. <input type="submit" class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" />
  373. </span>
  374. </p>
  375.  
  376. </div>
  377. <?php
  378. }
  379. }
  380.  
  381. /**
  382. * Add 'On Sale Filter to Product list in Admin
  383. */
  384. add_filter( 'parse_query', 'on_sale_filter' );
  385. function on_sale_filter( $query ) {
  386. global $pagenow, $typenow, $wp_query;
  387.  
  388. if ( $typenow=='product' && isset($_GET['onsale_check']) && $_GET['onsale_check'] ) :
  389.  
  390. if ( $_GET['onsale_check'] == 'yes' ) :
  391. $query->query_vars['meta_compare'] = '>';
  392. $query->query_vars['meta_value'] = 0;
  393. $query->query_vars['meta_key'] = '_sale_price';
  394. endif;
  395.  
  396. if ( $_GET['onsale_check'] == 'no' ) :
  397. $query->query_vars['meta_value'] = '';
  398. $query->query_vars['meta_key'] = '_sale_price';
  399. endif;
  400.  
  401. endif;
  402. }
  403.  
  404. add_action('restrict_manage_posts','woocommerce_products_by_on_sale');
  405. function woocommerce_products_by_on_sale() {
  406. global $typenow, $wp_query;
  407. if ( $typenow=='product' ) :
  408.  
  409. $onsale_check_yes = '';
  410. $onsale_check_no = '';
  411.  
  412. if ( isset( $_GET['onsale_check'] ) && $_GET['onsale_check'] == 'yes' ) :
  413. $onsale_check_yes = ' selected="selected"';
  414. endif;
  415.  
  416. if ( isset( $_GET['onsale_check'] ) && $_GET['onsale_check'] == 'no' ) :
  417. $onsale_check_no = ' selected="selected"';
  418. endif;
  419.  
  420. $output = "<select name='onsale_check' id='dropdown_onsale_check'>";
  421. $output .= '<option value="">'.__('Show all products (Sale Filter)', 'woothemes').'</option>';
  422. $output .= '<option value="yes"'.$onsale_check_yes.'>'.__('Show products on sale', 'woothemes').'</option>';
  423. $output .= '<option value="no"'.$onsale_check_no.'>'.__('Show products not on sale', 'woothemes').'</option>';
  424. $output .= '</select>';
  425.  
  426. echo $output;
  427.  
  428. endif;
  429. }
  430.  
  431.  
  432. // ADD IMAGE CATEGORY OPTION
  433. function yiw_add_cateogry_image_size( $options ) {
  434. $tmp = $options[ count($options)-1 ];
  435. unset( $options[ count($options)-1 ] );
  436.  
  437. $options[] = array(
  438. 'name' => __( 'Category Thumbnails', 'woocommerce' ),
  439. 'desc' => __('This size is usually used for the category list on the product page.', 'woocommerce'),
  440. 'id' => 'woocommerce_category_image',
  441. 'css' => '',
  442. 'type' => 'image_width',
  443. 'std' => '225',
  444. 'desc_tip' => true,
  445. );
  446.  
  447. $options[] = $tmp;
  448.  
  449. return $options;
  450. }
  451. add_filter( 'woocommerce_catalog_settings', 'yiw_add_cateogry_image_size' );
  452.  
  453. function woocommerce_subcategory_thumbnail( $category ) {
  454. global $woocommerce;
  455.  
  456. $small_thumbnail_size = apply_filters( 'single_product_small_thumbnail_size', 'shop_category' );
  457. $image_width = $woocommerce->get_image_size( 'shop_category_image_width' );
  458. $image_height = $woocommerce->get_image_size( 'shop_category_image_height' );
  459.  
  460. $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
  461.  
  462. if ( $thumbnail_id ) {
  463. $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size );
  464. $image = $image[0];
  465. } else {
  466. $image = woocommerce_placeholder_img_src();
  467. }
  468.  
  469. echo '<img src="' . $image . '" alt="' . $category->name . '" width="' . $image_width . '" height="' . $image_height . '" />';
  470. }
  471.  
  472. if( !function_exists( 'yiw_out_of_stock_flash' ) ) :
  473. function yiw_out_of_stock_flash() {
  474. woocommerce_get_template( 'loop/out-of-stock-flash.php' );
  475. }
  476. endif;
  477. add_action( 'woocommerce_before_shop_loop_item_title', 'yiw_out_of_stock_flash', 10 );
  478.  
  479. function yiw_star_rating() {
  480.  
  481. global $woocommerce,$post, $wpdb;
  482. if ( comments_open() ) :
  483.  
  484. $count = $wpdb->get_var("
  485. SELECT COUNT(meta_value) FROM $wpdb->commentmeta
  486. LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
  487. WHERE meta_key = 'rating'
  488. AND comment_post_ID = $post->ID
  489. AND comment_approved = '1'
  490. AND meta_value > 0
  491. ");
  492.  
  493. $rating = $wpdb->get_var("
  494. SELECT SUM(meta_value) FROM $wpdb->commentmeta
  495. LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
  496. WHERE meta_key = 'rating'
  497. AND comment_post_ID = $post->ID
  498. AND comment_approved = '1'
  499. ");
  500.  
  501. if ( $count > 0 ) :
  502.  
  503. $average = number_format($rating / $count, 2);
  504.  
  505. echo '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"';
  506. if ( is_product() ) :
  507. echo ' class="single_product_rating"';
  508. else :
  509. echo ' class="loop_rating"';
  510. endif;
  511. echo '>';
  512.  
  513. echo '<div class="star-rating" title="'.sprintf(__('Rated %s out of 5', 'woocommerce'), $average).'"><span style="width:'.($average*16).'px"><span itemprop="ratingValue" class="rating">'. $average.'</span> '.__('out of 5', 'woocommerce').'</span></div>';
  514.  
  515. echo '</div>';
  516.  
  517. endif;
  518.  
  519. endif;
  520.  
  521. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement