Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 67.39 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage KLEO
  5. * @author SeventhQueen <themesupport@seventhqueen.com>
  6. * @since 1.4
  7. */
  8.  
  9. // Load WooCommerce custom stylsheet
  10. if ( ! is_admin() ) {
  11. if ( version_compare( WOOCOMMERCE_VERSION, "2.1" ) < 0 ) {
  12. define( 'WOOCOMMERCE_USE_CSS', false );
  13. }
  14. add_action( 'wp_enqueue_scripts', 'kleo_load_woocommerce_css', 20 );
  15. }
  16.  
  17. if ( ! function_exists( 'kleo_load_woocommerce_css' ) ) {
  18. function kleo_load_woocommerce_css() {
  19.  
  20. $min = sq_option( 'dev_mode', 0 ) == 0 ? '.min' : '';
  21.  
  22. /* If remove query option is ON */
  23. if ( sq_option( 'perf_remove_query', 0 ) == 1 ) {
  24. $version = null;
  25. } else {
  26. $version = KLEO_THEME_VERSION;
  27. }
  28.  
  29. wp_deregister_style( 'woocommerce-layout' );
  30. wp_dequeue_style( 'woocommerce-layout' );
  31. wp_deregister_style( 'woocommerce-smallscreen' );
  32. wp_dequeue_style( 'woocommerce-smallscreen' );
  33. wp_deregister_style( 'woocommerce-general' );
  34. wp_dequeue_style( 'woocommerce-general' );
  35. wp_register_style( 'kleo-woocommerce', get_template_directory_uri() . '/woocommerce/assets/css/woocommerce' . $min . '.css', array(), $version );
  36. wp_enqueue_style( 'kleo-woocommerce' );
  37. }
  38. }
  39.  
  40. //de-register PrettyPhoto - we will use our own
  41. add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
  42.  
  43. function my_deregister_styles() {
  44. wp_deregister_style( 'woocommerce_prettyPhoto_css' );
  45. wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
  46. wp_dequeue_script( 'prettyPhoto' );
  47. wp_dequeue_script( 'prettyPhoto-init' );
  48. }
  49.  
  50. if ( ! function_exists( 'checked_environment' ) ) {
  51. // Check WooCommerce is installed first
  52. add_action( 'plugins_loaded', 'checked_environment' );
  53.  
  54. function checked_environment() {
  55. if ( ! class_exists( 'woocommerce' ) ) {
  56. wp_die( 'WooCommerce must be installed' );
  57. }
  58. }
  59. }
  60.  
  61. /* Add theme support for single page images */
  62. if( sq_option( 'woo_prod_zoom', 0 ) == 1 ) {
  63. add_theme_support( 'wc-product-gallery-zoom' );
  64. }
  65. if( sq_option( 'woo_prod_lightbox', 0 ) == 1 ) {
  66. add_theme_support( 'wc-product-gallery-lightbox' );
  67. add_filter( 'woocommerce_single_product_image_gallery_classes', 'sq_woo_gallery_name_filter' );
  68. }
  69. function sq_woo_gallery_name_filter( $classes = array() ) {
  70. $classes[] = 'photoswipe-enabled';
  71. return $classes;
  72. }
  73.  
  74.  
  75.  
  76. /* Admin scripts */
  77.  
  78. if ( is_admin() ) {
  79. //remove backend options by removing them from the config array
  80. add_filter( 'woocommerce_general_settings', 'kleo_woocommerce_general_settings_filter' );
  81. add_filter( 'woocommerce_page_settings', 'kleo_woocommerce_general_settings_filter' );
  82. add_filter( 'woocommerce_catalog_settings', 'kleo_woocommerce_general_settings_filter' );
  83. add_filter( 'woocommerce_inventory_settings', 'kleo_woocommerce_general_settings_filter' );
  84. add_filter( 'woocommerce_shipping_settings', 'kleo_woocommerce_general_settings_filter' );
  85. add_filter( 'woocommerce_tax_settings', 'kleo_woocommerce_general_settings_filter' );
  86.  
  87. function kleo_woocommerce_general_settings_filter( $options ) {
  88. $remove = array( 'woocommerce_enable_lightbox', 'woocommerce_frontend_css' );
  89.  
  90. foreach ( $options as $key => $option ) {
  91. if ( isset( $option['id'] ) && in_array( $option['id'], $remove ) ) {
  92. unset( $options[ $key ] );
  93. }
  94. }
  95.  
  96. return $options;
  97. }
  98.  
  99. // add product meta boxes
  100. add_filter( 'kleo_meta_boxes', 'kleo_woo_product_meta' );
  101.  
  102. function kleo_woo_product_meta( $meta_boxes ) {
  103. $prefix = '_kleo_';
  104. $meta_boxes[] = array(
  105. 'id' => 'theme_product',
  106. 'title' => 'Theme Product settings',
  107. 'pages' => array( 'product' ), // Post type
  108. 'context' => 'normal',
  109. 'priority' => 'default',
  110. 'show_names' => true, // Show field names on the left
  111. 'fields' => array(
  112. array(
  113. 'name' => 'Top bar status',
  114. 'desc' => 'Enable/disable site top bar',
  115. 'id' => $prefix . 'topbar_status',
  116. 'type' => 'select',
  117. 'options' => array(
  118. array( 'value' => '', 'name' => 'Default' ),
  119. array( 'value' => '1', 'name' => 'Visible' ),
  120. array( 'value' => '0', 'name' => 'Hidden' )
  121. ),
  122. 'value' => ''
  123. ),
  124. array(
  125. 'name' => 'Hide Header',
  126. 'desc' => 'Check to hide whole header area',
  127. 'id' => $prefix . 'hide_header',
  128. 'type' => 'checkbox',
  129. 'value' => '1'
  130. ),
  131. array(
  132. 'name' => 'Hide Footer',
  133. 'desc' => 'Check to hide whole footer area',
  134. 'id' => $prefix . 'hide_footer',
  135. 'type' => 'checkbox',
  136. 'value' => '1'
  137. ),
  138. array(
  139. 'name' => 'Hide Socket area',
  140. 'desc' => 'Check to hide the area after footer that contains copyright info.',
  141. 'id' => $prefix . 'hide_socket',
  142. 'type' => 'checkbox',
  143. 'value' => '1'
  144. ),
  145. array(
  146. 'name' => 'Custom Logo',
  147. 'desc' => 'Use a custom logo for this page only',
  148. 'id' => $prefix . 'logo',
  149. 'type' => 'file',
  150. ),
  151. array(
  152. 'name' => 'Custom Logo Retina',
  153. 'desc' => 'Use a custom retina logo for this page only',
  154. 'id' => $prefix . 'logo_retina',
  155. 'type' => 'file',
  156. ),
  157. array(
  158. 'name' => 'Transparent Main menu',
  159. 'desc' => 'Check to have Main menu background transparent.',
  160. 'id' => $prefix . 'transparent_menu',
  161. 'type' => 'checkbox',
  162. 'value' => '1'
  163. ),
  164.  
  165.  
  166. array(
  167. 'name' => 'Hide the title',
  168. 'desc' => 'Check to hide the title when displaying the post/page',
  169. 'id' => $prefix . 'title_checkbox',
  170. 'type' => 'checkbox',
  171. 'value' => '1'
  172. ),
  173. array(
  174. 'name' => 'Breadcrumb',
  175. 'desc' => '',
  176. 'id' => $prefix . 'hide_breadcrumb',
  177. 'type' => 'select',
  178. 'options' => array(
  179. array( 'value' => '', 'name' => 'Default' ),
  180. array( 'value' => '0', 'name' => 'Visible' ),
  181. array( 'value' => '1', 'name' => 'Hidden' )
  182. ),
  183. 'value' => ''
  184. ),
  185. array(
  186. 'name' => 'Hide information',
  187. 'desc' => 'Check to hide contact info in title section',
  188. 'id' => $prefix . 'hide_info',
  189. 'type' => 'checkbox',
  190. 'value' => '1'
  191. )
  192.  
  193. ),
  194. );
  195.  
  196. return $meta_boxes;
  197. }
  198.  
  199. } //end is_admin()
  200.  
  201.  
  202. // Remove WC sidebar
  203. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
  204.  
  205. //remove single product short description - excerpt
  206. if ( sq_option( 'woo_show_excerpt_single', 0 ) == 0 ) {
  207. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
  208. }
  209.  
  210.  
  211. //Single product data tabs
  212. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  213. add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 35 );
  214.  
  215. //Single product sharing
  216. $enabled_posts = sq_option( 'blog_share_types', array( 'post', 'product' ) );
  217. if ( sq_option( 'blog_social_share', 1 ) == 1 && in_array( 'product', (array) $enabled_posts ) ) {
  218. add_action( 'woocommerce_share', 'kleo_social_share', 10 );
  219. }
  220.  
  221. //sale badge
  222. remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
  223. add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_sale_flash' );
  224.  
  225. //catalog mode
  226. if ( sq_option( 'woo_catalog', '0' ) == '1' ) {
  227. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  228. remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
  229. remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
  230. remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
  231. remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
  232. remove_action( 'woocommerce_single_product_modal_summary', 'woocommerce_template_single_add_to_cart', 30 );
  233.  
  234. //disable prices
  235. if ( sq_option( 'woo_disable_prices', '0' ) == '1' ) {
  236. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
  237. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
  238. remove_action( 'woocommerce_single_product_modal_summary', 'woocommerce_template_single_price', 10 );
  239. }
  240. }
  241.  
  242.  
  243. //Category list change product count format
  244. add_filter( 'woocommerce_subcategory_count_html', 'kleo_woo_cat_count', 10, 2 );
  245. function kleo_woo_cat_count( $count, $category ) {
  246. return ' <mark class="count">' . $category->count . ' ' . __( 'Products', 'woocommerce' ) . '</mark>';
  247. }
  248.  
  249. /**
  250. * Adds required Woocommerce classes to body element
  251. *
  252. * @param array $classes
  253. *
  254. * @return array
  255. * @since 1.0
  256. */
  257. function kleo_woo_body_classes( $classes = '' ) {
  258.  
  259. if ( is_shop() || is_product_category() || is_product_tag() ) {
  260. $classes[] = 'kleo-shop-cols-' . sq_option( 'woo_shop_columns', '3' );
  261. }
  262.  
  263. return $classes;
  264.  
  265. }
  266.  
  267. add_filter( 'body_class', 'kleo_woo_body_classes' );
  268.  
  269.  
  270. // WooCommerce layout overrides
  271. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
  272. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
  273.  
  274. if ( ! function_exists( 'kleo_woocommerce_before_content' ) ) {
  275. // WooCommerce layout overrides
  276. add_action( 'woocommerce_before_main_content', 'kleo_woocommerce_before_content', 10 );
  277. function kleo_woocommerce_before_content() {
  278. //title section
  279. $title_arr = array();
  280. $shop_id = wc_get_page_id( 'shop' );
  281.  
  282. $title_arr['show_title'] = true;
  283.  
  284. //hide breadcrumb?
  285. $title_arr['show_breadcrumb'] = true;
  286. if ( sq_option( 'breadcrumb_status', 1 ) == 0 ) {
  287. $title_arr['show_breadcrumb'] = false;
  288. }
  289.  
  290. if ( is_shop() ) {
  291. $title_arr = kleo_prepare_title( $shop_id );
  292. } elseif ( is_product() ) {
  293. $title_arr = kleo_prepare_title();
  294. }
  295.  
  296. if ( sq_option( 'title_location', 'breadcrumb' ) == 'main' ) {
  297. $title_arr['show_title'] = false;
  298. } else {
  299. //title
  300. if ( is_shop() ) {
  301. $title = get_option( 'woocommerce_shop_page_title' );
  302. }
  303. if ( $shop_id && $shop_id != - 1 ) {
  304. if ( empty( $title ) ) {
  305. $title = get_the_title( $shop_id );
  306. }
  307. }
  308. if ( is_product_category() || is_product_tag() ) {
  309. global $wp_query;
  310. $tax = $wp_query->get_queried_object();
  311. $title = $tax->name;
  312. }
  313. }
  314.  
  315. if ( ! isset( $title ) ) {
  316. $title = __( "Shop", 'kleo_framework' );
  317. }
  318.  
  319. $title_arr['title'] = $title;
  320. $title_arr['link'] = '';
  321. if ( ( isset( $title_arr['show_breadcrumb'] ) && $title_arr['show_breadcrumb'] ) || isset( $title_arr['extra'] ) || $title_arr['show_title'] ) {
  322. echo kleo_title_section( $title_arr );
  323. }
  324.  
  325. remove_action( 'kleo_before_main_content', 'kleo_title_main_content' );
  326. if ( sq_option( 'title_location', 'breadcrumb' ) == 'breadcrumb' || get_cfield( 'title_checkbox', $shop_id ) == 1 ) {
  327. add_filter( 'woocommerce_show_page_title', '__return_false' );
  328. }
  329. get_template_part( 'page-parts/general-before-wrap' );
  330. }
  331. }
  332.  
  333. if ( ! function_exists( 'kleo_woocommerce_after_content' ) ) {
  334. // WooCommerce layout overrides
  335. add_action( 'woocommerce_after_main_content', 'kleo_woocommerce_after_content', 20 );
  336. function kleo_woocommerce_after_content() {
  337. get_template_part( 'page-parts/general-after-wrap' );
  338. }
  339. }
  340.  
  341. //Remove breadcrumb
  342. remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
  343.  
  344.  
  345. function kleo_woo_breadcrumb_data() {
  346. ob_start();
  347. woocommerce_breadcrumb( array(
  348. 'delimiter' => '<span class="sep"></span>',
  349. 'wrap_before' => '<div class="kleo_framework breadcrumb kleo-custom-breadcrumb" ' . ( is_single() ? 'itemprop="breadcrumb"' : '' ) . '>',
  350. 'wrap_after' => '</div>',
  351. ) );
  352. $breadcrumb = ob_get_clean();
  353.  
  354. return $breadcrumb;
  355. }
  356.  
  357. function kleo_woo_breadcrumb_replace() {
  358. if ( is_woocommerce() ) {
  359. add_filter( 'kleo_breadcrumb_data', 'kleo_woo_breadcrumb_data' );
  360. }
  361. }
  362.  
  363. add_filter( 'wp', 'kleo_woo_breadcrumb_replace' );
  364.  
  365.  
  366. //Change page layout to match theme options settings
  367. add_filter( 'kleo_page_layout', 'kleo_woo_change_layout' );
  368.  
  369. function kleo_woo_change_layout( $layout ) {
  370. global $kleo_config;
  371.  
  372. if ( is_woocommerce() ) {
  373.  
  374. $override_product = false;
  375.  
  376. if ( is_product() ) {
  377. if ( get_cfield( 'post_layout' ) && get_cfield( 'post_layout' ) != 'default' ) {
  378. $override_product = get_cfield( 'post_layout' );
  379. } elseif ( sq_option( 'woo_single_sidebar', 'default' ) != 'default' ) {
  380. $override_product = sq_option( 'woo_single_sidebar', 'default' );
  381. }
  382. }
  383.  
  384. $shop_id = wc_get_page_id( 'shop' );
  385. $shop_template = get_post_meta( $shop_id, '_wp_page_template', true );
  386.  
  387. if ( is_shop() && $shop_id && $shop_template && $shop_template != 'default'
  388. && isset( $kleo_config['tpl_map'][ $shop_template ] )
  389. ) {
  390.  
  391. $layout = $kleo_config['tpl_map'][ $shop_template ];
  392.  
  393. } elseif ( $override_product !== false ) {
  394. $layout = $override_product;
  395. } elseif ( ( is_product_category() || is_product_tag() ) && sq_option( 'woo_cat_sidebar', 'default' ) != 'default' ) {
  396. $layout = sq_option( 'woo_cat_sidebar', 'default' );
  397. } else {
  398. //switch to the general set in Theme options
  399. $woo_template = sq_option( 'woo_sidebar', 'default' );
  400. if ( $woo_template != 'default' ) {
  401. $layout = $woo_template;
  402. }
  403. }
  404.  
  405. //change default sidebar with Shop sidebar
  406. if ( is_active_sidebar( 'shop-1' ) ) {
  407. add_filter( 'kleo_sidebar_name', function() {
  408. return 'shop-1';
  409. } );
  410. }
  411. }
  412.  
  413. return $layout;
  414. }
  415.  
  416. /***************************************************
  417. * :: Add custom HTML to top header page set from Page edit
  418. ***************************************************/
  419.  
  420. add_action( 'kleo_before_main', 'kleo_shop_header', 8 );
  421.  
  422. function kleo_shop_header() {
  423.  
  424. if ( ! is_shop() ) {
  425. return;
  426. }
  427.  
  428. $shop_id = wc_get_page_id( 'shop' );
  429. if ( ! $shop_id ) {
  430. return;
  431. }
  432.  
  433. $page_header = get_cfield( 'header_content', $shop_id );
  434. if ( $page_header != '' ) {
  435. echo '<section class="kleo-shop-header container-wrap main-color">';
  436. echo do_shortcode( html_entity_decode( $page_header ) );
  437. echo '</section>';
  438. }
  439. }
  440.  
  441.  
  442. /***************************************************
  443. * :: Add custom HTML to bottom page set from Page edit
  444. ***************************************************/
  445.  
  446. add_action( 'kleo_after_main_content', 'kleo_woo_bottom_content', 12 );
  447.  
  448. function kleo_woo_bottom_content() {
  449.  
  450. if ( ! is_shop() ) {
  451. return;
  452. }
  453.  
  454. $shop_id = wc_get_page_id( 'shop' );
  455. if ( ! $shop_id ) {
  456. return;
  457. }
  458.  
  459. $page_bottom = get_cfield( 'bottom_content', $shop_id );
  460. if ( $page_bottom != '' ) {
  461. echo '<div class="kleo-page-bottom">';
  462. echo do_shortcode( html_entity_decode( $page_bottom ) );
  463. echo '</div>';
  464. }
  465. }
  466.  
  467.  
  468. // Change columns in product loop
  469. if ( ! function_exists( 'loop_columns' ) ) {
  470. function loop_columns() {
  471. return sq_option( 'woo_shop_columns', 3 );
  472. }
  473.  
  474. add_filter( 'loop_shop_columns', 'loop_columns' );
  475. }
  476. // Number of products per page
  477. $woo_per_page = sq_option( 'woo_shop_products', 15 );
  478. add_filter( 'loop_shop_per_page', function( $cols ) use ( $woo_per_page ) {
  479. return $woo_per_page;
  480. });
  481.  
  482. // Change columns in related products output
  483. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  484. add_action( 'woocommerce_after_single_product_summary', 'kleo_woocommerce_output_related_products', 20 );
  485.  
  486. if ( ! function_exists( 'kleo_woocommerce_output_related_products' ) ) {
  487. function kleo_woocommerce_output_related_products() {
  488. $items = sq_option( 'woo_related_columns', 3 );
  489. woocommerce_related_products( array( 'posts_per_page' => $items, 'columns' => $items ) );
  490. }
  491. }
  492.  
  493. // Change columns in upsell products output
  494. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
  495. add_action( 'woocommerce_after_single_product_summary', 'kleo_woocommerce_upsell_display', 20 );
  496.  
  497. if ( ! function_exists( 'kleo_woocommerce_upsell_display' ) ) {
  498. function kleo_woocommerce_upsell_display() {
  499. $items = sq_option( 'woo_upsell_columns', 3 );
  500. woocommerce_upsell_display( $items, $items );
  501. }
  502. }
  503.  
  504. // Change columns in upsell cross-sales output
  505. remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
  506. add_action( 'woocommerce_cart_collaterals', 'kleo_woocommerce_cross_sell_display' );
  507.  
  508. if ( ! function_exists( 'kleo_woocommerce_cross_sell_display' ) ) {
  509. function kleo_woocommerce_cross_sell_display() {
  510. $items = sq_option( 'woo_cross_columns', 3 );
  511. woocommerce_cross_sell_display( $items, $items );
  512. }
  513. }
  514.  
  515.  
  516. //cart.php template
  517. if ( version_compare( WOOCOMMERCE_VERSION, '2.3.8', '>=' ) ) {
  518. remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 );
  519. }
  520.  
  521.  
  522. /***************************************************
  523. * :: Product loop badges
  524. ***************************************************/
  525.  
  526. // On sale wrapper
  527. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
  528. add_action( 'woocommerce_before_shop_loop_item_title', 'kleo_woo_loop_badges', 10 );
  529. add_filter( 'woocommerce_sale_flash', 'kleo_woo_sale_flash', 10, 3 );
  530.  
  531. function kleo_woo_sale_flash( $data, $post, $product ) {
  532. $output = '<span class="kleo-sale-flash">' . $data . '</span>';
  533. if ( sq_option( 'woo_percentage_badge', 0 ) == 1 ) {
  534.  
  535. if ( $product->is_on_sale() && $product->product_type == 'variable' ) {
  536.  
  537. $available_variations = $product->get_available_variations();
  538. $max_percentage = 0;
  539. for ( $i = 0; $i < count( $available_variations ); ++ $i ) {
  540. $variation_id = $available_variations[ $i ]['variation_id'];
  541. $variable_product1 = new WC_Product_Variation( $variation_id );
  542. $regular_price = $variable_product1->regular_price;
  543. $sales_price = $variable_product1->sale_price;
  544. if ( $sales_price && $sales_price != '' ) {
  545. $partial_percentage = ( ( $regular_price - $sales_price ) / $regular_price ) * 100;
  546. if ( $partial_percentage > $max_percentage ) {
  547. $max_percentage = $partial_percentage;
  548. }
  549. }
  550. }
  551. $percentage = round( $max_percentage );
  552. } elseif ( $product->is_on_sale() && $product->product_type == 'simple' ) {
  553. $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
  554. } elseif ( $product->is_on_sale() && $product->product_type == 'external' ) {
  555. $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
  556. }
  557.  
  558. $output = '<span class="onsale percentage-badge">' . __( 'SAVE NOW', 'kleo_framework' ) . '<br>' .
  559. '<span class="big">' . $percentage . '%</span></span>';
  560. }
  561.  
  562. return $output;
  563. }
  564.  
  565. if ( ! function_exists( 'kleo_woo_loop_badges' ) ) {
  566. function kleo_woo_loop_badges() {
  567. global $product, $post;
  568. if ( kleo_woo_out_of_stock() ) {
  569.  
  570. echo '<span class="out-of-stock-badge">' . __( 'Out of stock', 'woocommerce' ) . '</span>';
  571.  
  572. } else if ( $product->is_on_sale() ) {
  573.  
  574. wc_get_template( 'loop/sale-flash.php' );
  575.  
  576. } else if ( ! $product->get_price() and sq_option( 'woo_free_badge', 1 ) == 1 ) {
  577.  
  578. echo '<span class="free-badge">' . __( 'Free', 'woocommerce' ) . '</span>';
  579.  
  580. } else if ( sq_option( 'woo_new_badge', 1 ) == 1 ) {
  581.  
  582. $postdate = get_the_time( 'Y-m-d' ); // Post date
  583. $postdatestamp = strtotime( $postdate ); // Timestamped post date
  584. $newness = sq_option( 'woo_new_days', 7 ); // Number of days to treat a product as new
  585.  
  586. if ( ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdatestamp ) {
  587. echo '<span class="new-badge">' . __( 'New', 'kleo_framework' ) . '</span>';
  588. }
  589.  
  590. }
  591. }
  592. }
  593.  
  594. function kleo_woo_out_of_stock() {
  595. global $post;
  596. $post_id = $post->ID;
  597. $stock_status = get_post_meta( $post_id, '_stock_status', true );
  598.  
  599. if ( $stock_status == 'outofstock' ) {
  600. return true;
  601. } else {
  602. return false;
  603. }
  604. }
  605.  
  606.  
  607. /***************************************************
  608. * :: Content-product hooks
  609. ***************************************************/
  610.  
  611. remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
  612. add_action( 'woocommerce_shop_loop_item_title', 'kleo_woo_template_loop_product_cats', 9 );
  613. add_action( 'woocommerce_shop_loop_item_title', 'kleo_woo_template_loop_product_title', 10 );
  614.  
  615.  
  616. /**
  617. * Show the product categories in the product loop.
  618. */
  619. if ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) >= 0 ) {
  620. function kleo_woo_template_loop_product_cats() {
  621. global $post;
  622. $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
  623. echo wc_get_product_category_list( $post->ID, ', ', '<span class="posted_in">' . _n( '', '', $size, 'woocommerce' ) . ' ', '</span>' );
  624. }
  625. } else {
  626. function kleo_woo_template_loop_product_cats() {
  627. global $product, $post;
  628. $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
  629. echo $product->get_categories( ', ', '<span class="posted_in">' . _n( '', '', $size, 'woocommerce' ) . ' ', '</span>' );
  630. }
  631. }
  632.  
  633. /**
  634. * Show the product title in the product loop.
  635. */
  636. function kleo_woo_template_loop_product_title() {
  637. echo '<h3><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>';
  638. }
  639.  
  640.  
  641. /***************************************************
  642. * :: Product images
  643. ***************************************************/
  644.  
  645. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
  646. add_action( 'woocommerce_before_shop_loop_item_title', 'kleo_woo_thumb_image', 10 );
  647. add_action( 'woocommerce_before_shop_loop_item_title', 'kleo_woo_first_image', 11 );
  648.  
  649. function kleo_woo_thumb_image() {
  650. echo '<div class="kleo-woo-image kleo-woo-front-image">' . woocommerce_get_product_thumbnail() . '</div>';
  651. }
  652.  
  653. function kleo_woo_first_image() {
  654. if ( kleo_woo_get_first_image() != '' ) {
  655. echo '<div class="kleo-woo-image kleo-woo-back-image">' . kleo_woo_get_first_image() . '</div>';
  656. }
  657. }
  658.  
  659. function kleo_woo_get_first_image() {
  660.  
  661. global $product, $post;
  662. if ( version_compare( WOOCOMMERCE_VERSION, "2.0.0" ) >= 0 ) {
  663.  
  664. $image = '';
  665. if ( version_compare( WOOCOMMERCE_VERSION, "3.0.0" ) >= 0 ) {
  666. $attachment_ids = $product->get_gallery_image_ids();
  667. } else {
  668. $attachment_ids = $product->get_gallery_attachment_ids();
  669. }
  670. $img_count = 0;
  671.  
  672. if ( $attachment_ids ) {
  673. foreach ( $attachment_ids as $attachment_id ) {
  674.  
  675. if ( get_post_meta( $attachment_id, '_woocommerce_exclude_image', true ) ) {
  676. continue;
  677. }
  678.  
  679. $image = wp_get_attachment_image( $attachment_id, 'shop_catalog' );
  680.  
  681. $img_count ++;
  682.  
  683. if ( $img_count == 1 ) {
  684. break;
  685. }
  686.  
  687. }
  688. }
  689. } else {
  690.  
  691. $attachments = get_posts( array(
  692. 'post_type' => 'attachment',
  693. 'numberposts' => - 1,
  694. 'post_status' => null,
  695. 'post_parent' => $post->ID,
  696. 'post__not_in' => array( get_post_thumbnail_id() ),
  697. 'post_mime_type' => 'image',
  698. 'orderby' => 'menu_order',
  699. 'order' => 'ASC'
  700. ) );
  701.  
  702. $img_count = 0;
  703.  
  704. if ( $attachments ) {
  705. foreach ( $attachments as $attachment ) {
  706.  
  707. if ( get_post_meta( $attachment->ID, '_woocommerce_exclude_image', true ) == 1 ) {
  708. continue;
  709. }
  710.  
  711. $image = wp_get_attachment_image( $attachment->ID, 'shop_catalog' );
  712.  
  713. $img_count ++;
  714.  
  715. if ( $img_count == 1 ) {
  716. break;
  717. }
  718.  
  719. }
  720.  
  721. }
  722. }
  723.  
  724. return $image;
  725. }
  726.  
  727.  
  728. /***************************************************
  729. * :: Wishlist
  730. ***************************************************/
  731.  
  732. add_action( 'woocommerce_before_shop_loop_item', 'kleo_woo_wishlist', 11 );
  733.  
  734. function kleo_woo_wishlist() {
  735. if ( in_array( 'yith-woocommerce-wishlist/init.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
  736. echo do_shortcode( '[yith_wcwl_add_to_wishlist]' );
  737. }
  738. }
  739.  
  740. add_action( 'yith_wcwl_after_wishlist_share', 'kleo_woo_wishlist_share' );
  741.  
  742. function kleo_woo_wishlist_share() {
  743. global $yith_wcwl;
  744. if ( get_option( 'yith_wcwl_share_fb' ) == 'yes' || get_option( 'yith_wcwl_share_twitter' ) == 'yes' || get_option( 'yith_wcwl_share_pinterest' ) == 'yes' || get_option( 'yith_wcwl_share_googleplus' ) == 'yes' || get_option( 'yith_wcwl_share_email' ) == 'yes' ) {
  745. $url = $yith_wcwl->get_wishlist_url();
  746. $url .= get_option( 'permalink-structure' ) != '' ? '&amp;user_id=' : '?user_id=';
  747. $url .= get_current_user_id();
  748. $normal_url = $url;
  749. $url = urlencode( $url );
  750. $title = urlencode( get_option( 'yith_wcwl_socials_title' ) );
  751. $twitter_summary = str_replace( '%wishlist_url%', '', get_option( 'yith_wcwl_socials_text' ) );
  752. $summary = urlencode( str_replace( '%wishlist_url%', $normal_url, get_option( 'yith_wcwl_socials_text' ) ) );
  753. $imageurl = urlencode( get_option( 'yith_wcwl_socials_image_url' ) );
  754.  
  755. $html = '<div class="share-links kleo-wishlist-share">';
  756. $html .= apply_filters( 'yith_wcwl_socials_share_title', '<div class="hr-title hr-full"><abbr>' . __( "Social share", "kleo_framework" ) . '</abbr></div>' );
  757.  
  758.  
  759. if ( get_option( 'yith_wcwl_share_fb' ) == 'yes' ) {
  760. $html .= '<span class="kleo-facebook"><a target="_blank" class="facebook" href="https://www.facebook.com/sharer.php?s=100&amp;p[title]=' . $title . '&amp;p[url]=' . $url . '&amp;p[summary]=' . $summary . '&amp;p[images][0]=' . $imageurl . '" title="' . __( 'Facebook', 'yit' ) . '"><i class="icon-facebook"></i></a></span>';
  761. }
  762.  
  763. if ( get_option( 'yith_wcwl_share_twitter' ) == 'yes' ) {
  764. $html .= '<span class="kleo-twitter"><a target="_blank" class="twitter" href="https://twitter.com/share?url=' . $url . '&amp;text=' . $twitter_summary . '" title="' . __( 'Twitter', 'yit' ) . '"><i class="icon-twitter"></i></a></span>';
  765. }
  766.  
  767. if ( get_option( 'yith_wcwl_share_pinterest' ) == 'yes' ) {
  768. $html .= '<span class="kleo-pinterest"><a target="_blank" class="pinterest" href="http://pinterest.com/pin/create/button/?url=' . $url . '&amp;description=' . $summary . '&media=' . $imageurl . '" onclick="window.open(this.href); return false;"><i class="icon-pinterest-circled"></i></a></span>';
  769. }
  770.  
  771. if ( get_option( 'yith_wcwl_share_googleplus' ) == 'yes' ) {
  772. $html .= '<span class="kleo-googleplus"><a target="_blank" class="googleplus" href="https://plus.google.com/share?url=' . $url . '&amp;title="' . $title . '" onclick=\'javascript:window.open(this.href, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600");return false;\'><i class="icon-gplus"></i></a></span>';
  773. }
  774.  
  775. if ( get_option( 'yith_wcwl_share_email' ) == 'yes' ) {
  776. $html .= '<span class="kleo-mail"><a target="_blank" class="post_share_email" href="mailto:?subject=' . $title . '&body=' . $url . '"><i class="icon-mail"></i></a></span>';
  777. }
  778.  
  779. $html .= '</div>';
  780.  
  781. echo $html;
  782. }
  783.  
  784. }
  785.  
  786.  
  787. /***************************************************
  788. * :: Quick view
  789. ***************************************************/
  790.  
  791. add_action( 'woocommerce_after_shop_loop_item', 'kleo_woo_quickview_button', 20 );
  792.  
  793. function kleo_woo_quickview_button() {
  794. echo kleo_woo_get_quickview_button();
  795.  
  796. //Enqueue variations script for quick view
  797. wp_enqueue_script( 'wc-add-to-cart-variation' );
  798. }
  799.  
  800. function kleo_woo_get_quickview_button( $post_id = null, $tooltip = null ) {
  801. if ( ! $post_id ) {
  802. global $post;
  803. $post_id = $post->ID;
  804. }
  805. if ( $tooltip === true ) {
  806. $tooltip_data = ' data-toggle="tooltip" data-placement="top" data-title="' . __( "Quick View", "kleo_framework" ) . '" data-container="body"';
  807. } else {
  808. $tooltip_data = '';
  809. }
  810.  
  811. return '<div class="quick-view hover-tip"' . $tooltip_data . ' data-prod="' . $post_id . '">' . __( 'Quick View', 'kleo_framework' ) . '</div>';
  812. }
  813.  
  814. // Quickview Ajax
  815. add_action( 'wp_ajax_woo_quickview', 'kleo_woo_quickview' );
  816. add_action( 'wp_ajax_nopriv_woo_quickview', 'kleo_woo_quickview' );
  817.  
  818. function kleo_woo_quickview() {
  819. global $post, $product;
  820.  
  821. $prod_id = $_POST["product"];
  822. $post = get_post( $prod_id );
  823. $product = wc_get_product( $prod_id );
  824.  
  825. ob_start();
  826. wc_get_template( 'content-single-product-modal.php' );
  827. $output = ob_get_contents();
  828. ob_end_clean();
  829.  
  830. echo $output;
  831. die();
  832. }
  833.  
  834. if ( ! function_exists( 'kleo_social_share' ) ) {
  835. function kleo_social_share() {
  836. ?>
  837.  
  838. <div class="share-links">
  839. <div class="hr-title hr-full"><abbr><?php _e( "Social share", "kleo_framework" ); ?></abbr></div>
  840.  
  841. <?php if ( sq_option( 'blog_social_share_facebook', 1 ) ) : ?>
  842. <span class="kleo-facebook">
  843. <a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" class="post_share_facebook"
  844. onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=220,width=600');return false;">
  845. <i class="icon-facebook"></i>
  846. </a>
  847. </span>
  848. <?php endif; ?>
  849.  
  850. <?php if ( sq_option( 'blog_social_share_twitter', 1 ) ) : ?>
  851. <span class="kleo-twitter">
  852. <a href="https://twitter.com/share?url=<?php the_permalink(); ?>" class="post_share_twitter"
  853. onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=260,width=600');return false;">
  854. <i class="icon-twitter"></i>
  855. </a>
  856. </span>
  857. <?php endif; ?>
  858.  
  859. <?php if ( sq_option( 'blog_social_share_googleplus', 1 ) ) : ?>
  860. <span class="kleo-googleplus">
  861. <a href="https://plus.google.com/share?url=<?php the_permalink(); ?>"
  862. onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
  863. <i class="icon-gplus"></i>
  864. </a>
  865. </span>
  866. <?php endif; ?>
  867.  
  868. <?php if ( sq_option( 'blog_social_share_pinterest', 1 ) ) : ?>
  869. <span class="kleo-pinterest">
  870. <a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php if ( function_exists( 'the_post_thumbnail' ) ) {
  871. echo wp_get_attachment_url( get_post_thumbnail_id() );
  872. } ?>&description=<?php echo strip_tags( get_the_title() ); ?>"
  873. onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
  874. <i class="icon-pinterest-circled"></i>
  875. </a>
  876. </span>
  877. <?php endif; ?>
  878.  
  879. <?php if ( sq_option( 'blog_social_share_linkedin', 0 ) ) : ?>
  880. <span class="kleo-linkedin">
  881. <a href="https://www.linkedin.com/shareArticle?url=<?php the_permalink(); ?>"
  882. class="post_share_linkedin"
  883. onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
  884. <i class="icon-linkedin"></i>
  885. </a>
  886. </span>
  887. <?php endif; ?>
  888.  
  889. <?php if ( sq_option( 'blog_social_share_whatsapp', 0 ) ) : ?>
  890. <span class="kleo-whatsapp visible-xs-inline visible-sm-inline">
  891. <a href="whatsapp://send?text=<?php the_permalink(); ?>" data-action="share/whatsapp/share">
  892. <i class="icon-whatsapp"></i>
  893. </a>
  894. </span>
  895. <?php endif; ?>
  896.  
  897. <?php if ( sq_option( 'blog_social_share_mail', 1 ) ) : ?>
  898. <span class="kleo-mail">
  899. <a href="mailto:?subject=<?php echo strip_tags( get_the_title() ); ?>&body=<?php the_permalink(); ?>"
  900. class="post_share_email">
  901. <i class="icon-mail"></i>
  902. </a>
  903. </span>
  904. <?php endif; ?>
  905. </div>
  906.  
  907. <?php
  908. }
  909. }
  910.  
  911.  
  912. add_action( 'woocommerce_single_product_modal_summary', 'woocommerce_template_single_price', 10 );
  913. add_action( 'woocommerce_single_product_modal_summary', 'woocommerce_template_single_excerpt', 20 );
  914. add_action( 'woocommerce_single_product_modal_summary', 'woocommerce_template_single_add_to_cart', 30 );
  915. add_action( 'woocommerce_single_product_modal_summary', 'woocommerce_template_single_meta', 40 );
  916.  
  917. $enabled_posts = sq_option( 'blog_share_types', array( 'post', 'product' ) );
  918. if ( sq_option( 'blog_social_share', 1 ) == 1 && in_array( 'product', (array) $enabled_posts ) ) {
  919. add_action( 'woocommerce_single_product_modal_summary', 'kleo_social_share', 50 );
  920. }
  921.  
  922.  
  923. /***************************************************
  924. * :: Prev/Next products
  925. ***************************************************/
  926.  
  927. if ( ! function_exists( 'kleo_product_nav' ) ) :
  928. /**
  929. * Display navigation to next/previous post when applicable.
  930. *
  931. * @since Kleo 1.0
  932. *
  933. * @return void
  934. */
  935. function kleo_product_nav( $same_cat = false ) {
  936.  
  937. if ( ! is_product() ) {
  938. return;
  939. }
  940. // Don't print empty markup if there's nowhere to navigate.
  941. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( $same_cat, '', true );
  942. $next = get_adjacent_post( $same_cat, '', false );
  943.  
  944. if ( ! $next && ! $previous ) {
  945. return;
  946. }
  947. ?>
  948.  
  949. <nav class="pagination-sticky product-navigation" role="navigation">
  950. <?php
  951. if ( is_attachment() ) :
  952. previous_post_link( '%link', __( '<span id="older-nav">Go back</span>', 'kleo_framework' ) );
  953. else :
  954.  
  955. if ( $previous ) {
  956. $prev_img = get_the_post_thumbnail( $previous->ID, 'thumbnail' );
  957. $prev_img = $prev_img ? '<span class="nav-image">' . $prev_img . '</span>' : '';
  958. previous_post_link( '%link', '<span id="older-nav">' . $prev_img . '<span class="outter-title"><span class="entry-title">' . get_the_title( $previous->ID ) . '</span></span></span>', $same_cat );
  959. }
  960.  
  961. if ( $next ) {
  962. $next_img = get_the_post_thumbnail( $next->ID, 'thumbnail' );
  963. $next_img = $next_img ? '<span class="nav-image">' . $next_img . '</span>' : '';
  964. next_post_link( '%link', '<span id="newer-nav">' . $next_img . '<span class="outter-title"><span class="entry-title">' . get_the_title( $next->ID ) . '</span></span></span>', $same_cat );
  965. }
  966.  
  967. endif;
  968. ?>
  969. </nav><!-- .navigation -->
  970.  
  971. <?php
  972. }
  973. endif;
  974. if ( sq_option( 'woo_product_navigation', 1 ) == 1 ) :
  975. add_action( 'kleo_after_main', 'kleo_product_nav', 11 );
  976. endif;
  977.  
  978.  
  979. /***************************************************
  980. * :: Header menu cart
  981. ***************************************************/
  982.  
  983. if ( sq_option( 'woo_cart_location', 'primary' ) != 'off' ) {
  984. if(!is_admin()) {
  985. add_filter('wp_nav_menu_items', 'kleo_woo_header_cart', 9, 2);
  986. }
  987. }
  988.  
  989.  
  990.  
  991. if ( ! function_exists( 'kleo_woo_header_cart' ) ) {
  992. /**
  993. * Add search to menu
  994. *
  995. * @param string $items
  996. * @param object $args
  997. *
  998. * @return string
  999. */
  1000. function kleo_woo_header_cart( $items, $args ) {
  1001. $cart_location = sq_option( 'woo_cart_location', 'primary' );
  1002.  
  1003. if ( $args->theme_location == $cart_location ) {
  1004. $items .= kleo_woo_get_mini_cart();
  1005. }
  1006.  
  1007. return $items;
  1008. }
  1009. }
  1010.  
  1011.  
  1012. /* ADD TO CART HEADER RELOAD */
  1013. if ( ! function_exists( 'kleo_woo_header_cart_fragment' ) ) {
  1014. function kleo_woo_header_cart_fragment( $fragments ) {
  1015.  
  1016. $output = kleo_woo_get_mini_cart();
  1017. $fragments['.kleo-toggle-menu.shop-drop'] = $output;
  1018.  
  1019. $fragments['.cart-contents.mheader'] = kleo_woo_get_mobile_icon();
  1020.  
  1021. return $fragments;
  1022.  
  1023. }
  1024.  
  1025. add_filter( 'woocommerce_add_to_cart_fragments', 'kleo_woo_header_cart_fragment' );
  1026. }
  1027.  
  1028.  
  1029. if ( ! function_exists( 'kleo_woo_get_mini_cart' ) ) {
  1030. function kleo_woo_get_mini_cart( $just_inner = false ) {
  1031.  
  1032. global $woocommerce;
  1033.  
  1034.  
  1035. //Enqueue variations script for quick view
  1036. wp_enqueue_script( 'wc-add-to-cart-variation' );
  1037.  
  1038. $cart_output = "";
  1039. $cart_total = $woocommerce->cart->get_cart_total();
  1040. $cart_count = $woocommerce->cart->cart_contents_count;
  1041. $cart_count_text = kleo_product_items_text( $cart_count );
  1042.  
  1043. $cart_has_items = '';
  1044. if ( $cart_count != "0" ) {
  1045. $cart_has_items = ' has-products';
  1046. }
  1047.  
  1048. if ( ! $just_inner ) {
  1049. $cart_output .= '<li class="menu-item kleo-toggle-menu shop-drop">'
  1050. . '<a class="cart-contents js-activated" href="' . wc_get_cart_url() . '" title="' . __( "View Cart", "woocommerce" ) . '">'
  1051. . '<span class="cart-items' . $cart_has_items . '"><i class="icon icon-basket-full-alt"></i> ';
  1052.  
  1053. if ( $cart_count != "0" ) {
  1054. $cart_output .= "<span class='kleo-notifications new-alert'>" . $cart_count . "</span>";
  1055. }
  1056.  
  1057. $cart_output .= '</span> <span class="caret"></span>'
  1058. . '</a>'
  1059. . '<ul class="kleo-toggle-submenu">';
  1060. }
  1061.  
  1062. $cart_output .= '<li>'
  1063. . '<div class="kleo-minicart">';
  1064.  
  1065. if ( $cart_count != "0" ) {
  1066.  
  1067. $cart_output .= '<div class="minicart-header">' . $cart_count_text . ' ' . __( 'in the shopping cart', 'kleo_framework' ) . '</div>';
  1068.  
  1069. $cart_output .= '<div class="minicart-contents">';
  1070.  
  1071. foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $cart_item ) {
  1072.  
  1073. $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  1074. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
  1075.  
  1076. if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
  1077.  
  1078. $cart_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  1079.  
  1080. $product_title = $cart_product->get_title();
  1081. $product_short_title = ( strlen( $product_title ) > 25 ) ? substr( $product_title, 0, 22 ) . '...' : $product_title;
  1082. $product_short_title = apply_filters( 'woocommerce_cart_item_name', $product_short_title, $cart_item, $cart_item_key );
  1083.  
  1084. $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $cart_product->get_image(), $cart_item, $cart_item_key );
  1085. $product_price = apply_filters( 'woocommerce_cart_item_price', wc_price( $cart_product->get_price() ), $cart_item, $cart_item_key );
  1086. $product_quantity = apply_filters( 'woocommerce_cart_item_quantity', $cart_item['quantity'], $cart_item_key, $cart_item );
  1087.  
  1088. if ( $cart_product->exists() && $cart_item['quantity'] > 0 ) {
  1089. $cart_output .= '<div class="cart-product clearfix">';
  1090. $cart_output .= '<figure><a class="cart-product-img" href="' . get_permalink( $cart_item['product_id'] ) . '">' . $thumbnail . '</a></figure>';
  1091. $cart_output .= '<div class="cart-product-details">';
  1092. $cart_output .= '<div class="cart-product-title"><a href="' . get_permalink( $cart_item['product_id'] ) . '">' . $product_short_title . '</a></div>';
  1093. $cart_output .= '<div class="cart-product-price">' . __( "Price", "woocommerce" ) . ' ' . $product_price . '</div>';
  1094. $cart_output .= '<div class="cart-product-quantity">' . __( 'Quantity', 'woocommerce' ) . ' ' . $product_quantity . '</div>';
  1095. $cart_output .= '</div>';
  1096. $cart_output .= kleo_woo_get_quickview_button( $cart_item['product_id'], false );
  1097.  
  1098. $cart_output .= apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
  1099. '<a href="%s" class="remove" title="%s" data-product_id="%s" data-product_sku="%s">&times;</a>',
  1100. esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
  1101. __( 'Remove this item', 'woocommerce' ),
  1102. esc_attr( $product_id ),
  1103. esc_attr( $_product->get_sku() )
  1104. ), $cart_item_key );
  1105. //$cart_output .= apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="remove" title="%s">&times;</a>', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'woocommerce' ) ), $cart_item_key );
  1106.  
  1107. $cart_output .= '</div>';
  1108. }
  1109. }
  1110. }
  1111.  
  1112. $cart_output .= '</div>';
  1113.  
  1114. $cart_output .= '<div class="minicart-total-checkout">' . __( 'Cart Subtotal', 'kleo_framework' ) . ' ' . $cart_total . '</div>';
  1115.  
  1116. $cart_output .= '<div class="minicart-buttons">';
  1117.  
  1118. if ( version_compare( WOOCOMMERCE_VERSION, '2.1.0' ) >= 0 ) {
  1119.  
  1120. $cart_output .= '<a class="btn btn-default" href="' . esc_url( wc_get_cart_url() ) . '"><span class="text">' . __( 'View Cart', 'woocommerce' ) . '</span></a>';
  1121. $cart_output .= '<a class="btn btn-highlight checkout-button" href="' . esc_url( wc_get_checkout_url() ) . '"><span class="text">' . __( 'Proceed to checkout', 'woocommerce' ) . '</span></a>';
  1122.  
  1123. } else {
  1124.  
  1125. $cart_output .= '<a class="btn btn-default" href="' . esc_url( $woocommerce->cart->get_cart_url() ) . '"><span class="text">' . __( 'View Cart', 'woocommerce' ) . '</span></a>';
  1126. $cart_output .= '<a class="btn btn-highlight" href="' . esc_url( $woocommerce->cart->get_checkout_url() ) . '"><span class="text">' . __( 'Proceed to checkout', 'woocommerce' ) . '</span></a>';
  1127.  
  1128. }
  1129.  
  1130. $cart_output .= '</div>';
  1131.  
  1132. } else {
  1133.  
  1134. $cart_output .= '<div class="minicart-header">' . __( 'Your shopping bag is empty.', 'kleo_framework' ) . '</div>';
  1135.  
  1136. $shop_page_url = "";
  1137. if ( version_compare( WOOCOMMERCE_VERSION, '2.1.0' ) >= 0 ) {
  1138. $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
  1139. } else {
  1140. $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
  1141. }
  1142.  
  1143. $cart_output .= '<div class="minicart-buttons">';
  1144.  
  1145. $cart_output .= '<a class="btn btn-default kleo-go-shop" href="' . esc_url( $shop_page_url ) . '"><span class="text">' . __( 'Go to the shop', 'kleo_framework' ) . '</span></a>';
  1146.  
  1147. $cart_output .= '</div>';
  1148.  
  1149. }
  1150.  
  1151. $cart_output .= '</div>'
  1152. . '</li>';
  1153.  
  1154. if ( ! $just_inner ) {
  1155. $cart_output .= '</ul>'
  1156. . '</li>';
  1157. }
  1158.  
  1159. return $cart_output;
  1160. }
  1161. }
  1162.  
  1163.  
  1164. function kleo_product_items_text( $count ) {
  1165.  
  1166. $product_item_text = "";
  1167.  
  1168. if ( $count > 1 ) {
  1169. $product_item_text = str_replace( '%', number_format_i18n( $count ), __( '% items', 'kleo_framework' ) );
  1170. } elseif ( $count == 0 ) {
  1171. $product_item_text = __( '0 items', 'kleo_framework' );
  1172. } else {
  1173. $product_item_text = __( '1 item', 'kleo_framework' );
  1174. }
  1175.  
  1176. return $product_item_text;
  1177.  
  1178. }
  1179.  
  1180.  
  1181. /* Mobile cart icons */
  1182. function kleo_woo_get_mobile_icon() {
  1183. global $woocommerce;
  1184. $cart_count = $woocommerce->cart->cart_contents_count;
  1185. $cart_has_items = '';
  1186. $output = '';
  1187.  
  1188. if ( $cart_count != "0" ) {
  1189. $cart_has_items = ' has-products';
  1190. }
  1191.  
  1192. $output .= '<a class="cart-contents mheader" href="' . wc_get_cart_url() . '" title="' . __( "View Cart", "woocommerce" ) . '">'
  1193. . '<span class="cart-items' . $cart_has_items . '"><i class="icon icon-basket-full-alt"></i> ';
  1194.  
  1195. if ( $cart_count != "0" ) {
  1196. $output .= "<span>" . $cart_count . "</span>";
  1197. }
  1198.  
  1199. $output .= '</span></a>';
  1200.  
  1201. return $output;
  1202. }
  1203.  
  1204. function kleo_woo_mobile_icon() {
  1205. echo kleo_woo_get_mobile_icon();
  1206. }
  1207.  
  1208. if ( sq_option( 'woo_mobile_cart', 1 ) == 1 ) {
  1209. add_action( 'kleo_mobile_header_icons', 'kleo_woo_mobile_icon' );
  1210. }
  1211.  
  1212.  
  1213. /* Remove items by AJAX */
  1214. add_action( 'wp_ajax_kleo_woo_rem_item', 'kleo_woo_remove_item' );
  1215. add_action( 'wp_ajax_nopriv_kleo_woo_rem_item', 'kleo_woo_remove_item' );
  1216.  
  1217. function kleo_woo_remove_item() {
  1218.  
  1219. global $woocommerce;
  1220. $response = array();
  1221.  
  1222. if ( ! isset( $_GET['kleo_item'] ) && ! isset( $_GET['_wpnonce'] ) ) {
  1223. exit;
  1224. }
  1225. $instance = WC()->cart;
  1226. $instance->set_quantity( $_GET['kleo_item'], 0 );
  1227. do_action( 'woocommerce_cart_item_removed', $_GET['kleo_item'], $instance );
  1228.  
  1229. $cart_count = $woocommerce->cart->cart_contents_count;
  1230. $response['count'] = $cart_count != 0 ? $cart_count : "";
  1231. $response['cart'] = kleo_woo_get_mini_cart( true );
  1232.  
  1233. //widget cart update
  1234. ob_start();
  1235. woocommerce_mini_cart();
  1236. $mini_cart = ob_get_clean();
  1237. $response['widget'] = '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>';
  1238.  
  1239. echo json_encode( $response );
  1240. exit;
  1241. }
  1242.  
  1243.  
  1244. if ( ! function_exists( 'kleo_checkout_steps' ) ) {
  1245. /**
  1246. * Print Woocommerce Checkout steps
  1247. */
  1248. function kleo_checkout_steps() {
  1249. ?>
  1250.  
  1251. <div class="checkout-steps">
  1252. <span class="step-cart"><a
  1253. href="<?php echo wc_get_cart_url(); ?>"><?php _e( 'Shopping Cart', 'kleo_framework' ); ?></a></span>
  1254. <i class="icon icon-angle-right"></i>
  1255. <span class="step-checkout"><?php _e( 'Checkout details', 'kleo_framework' ); ?></span>
  1256. <i class="icon icon-angle-right"></i>
  1257. <span class="step-complete"><?php _e( 'Order Complete', 'kleo_framework' ); ?></span>
  1258. </div>
  1259.  
  1260. <?php
  1261. }
  1262. }
  1263.  
  1264. add_action( 'woocommerce_before_cart', 'kleo_checkout_steps' );
  1265. add_action( 'woocommerce_before_checkout_page', 'kleo_checkout_steps' );
  1266.  
  1267.  
  1268. /***************************************************
  1269. * :: Custom main menu select for each page
  1270. ***************************************************/
  1271. function kleo_woo_set_custom_menu( $args = '' ) {
  1272.  
  1273. if ( 'primary' != $args['theme_location'] && 'secondary' != $args['theme_location'] ) {
  1274. return $args;
  1275. }
  1276.  
  1277. $shop_id = wc_get_page_id( 'shop' );
  1278.  
  1279. if ( is_shop() ) {
  1280.  
  1281. if ( 'primary' == $args['theme_location'] ) {
  1282. $menuslug = get_cfield( 'page_menu', $shop_id );
  1283.  
  1284. if ( ! empty( $menuslug ) && $menuslug != 'default' && is_nav_menu( $menuslug ) ) {
  1285. $args['menu'] = $menuslug;
  1286. }
  1287. } elseif ( 'secondary' == $args['theme_location'] ) {
  1288.  
  1289. $sec_menuslug = get_cfield( 'page_menu_secondary', $shop_id );
  1290.  
  1291. if ( ! empty( $sec_menuslug ) && $sec_menuslug != 'default' && is_nav_menu( $sec_menuslug ) ) {
  1292. $args['menu'] = $sec_menuslug;
  1293. }
  1294.  
  1295. }
  1296.  
  1297. }
  1298.  
  1299. return $args;
  1300. } // END function kleo_set_custom_menu($args = '')
  1301. add_filter( 'wp_nav_menu_args', 'kleo_woo_set_custom_menu', 11 );
  1302.  
  1303.  
  1304. /* Append dynamic CSS */
  1305. function kleo_woo_dynamic_css() {
  1306. $h1 = sq_option( 'font_h1' );
  1307. $extra_style = '';
  1308. $extra_style .= '.percentage-badge { color: ' . sq_option( 'woo_percent_color', '#fff' ) . ' !important; background: ' . sq_option( 'woo_percent_bg', '#000' ) . ' !important; }';
  1309. $extra_style .= 'body.single-product span.page-title { font-family: ' . $h1['font-family'] . ' !important; font-weight: ' . $h1['font-weight'] . ' !important; display:block; font-size: 26px; line-height: 34px; margin: 0; }';
  1310.  
  1311. return $extra_style;
  1312. }
  1313.  
  1314. add_filter( 'kleo_add_dynamic_style', 'kleo_woo_dynamic_css' );
  1315.  
  1316. function kleo_dynamic_alternate_func( $output, $section ) {
  1317. $output .= 'body.single-product span.page-title { color: ' . $section['headings'] . '; }';
  1318.  
  1319. return $output;
  1320. }
  1321.  
  1322. add_filter( 'kleo_dynamic_alternate', 'kleo_dynamic_alternate_func', 10, 2 );
  1323.  
  1324.  
  1325. /* Visual composer integration */
  1326.  
  1327. if ( defined( 'WPB_VC_VERSION' ) && version_compare( WPB_VC_VERSION, '4.4' ) < 0 ) {
  1328.  
  1329. /**** Order Tracking ***/
  1330.  
  1331. vc_map( array(
  1332. "name" => "Order Tracking",
  1333. "base" => "woocommerce_order_tracking",
  1334. "icon" => "icon-wpb-woocommerce_order_tracking",
  1335. "category" => 'Woocommerce',
  1336. "allowed_container_element" => 'vc_row',
  1337. "show_settings_on_create" => false
  1338. ) );
  1339.  
  1340. /*** Product price/cart button ***/
  1341.  
  1342. vc_map( array(
  1343. "name" => "Add to cart",
  1344. "base" => "add_to_cart",
  1345. "icon" => "icon-wpb-add_to_cart",
  1346. "category" => 'Woocommerce',
  1347. "allowed_container_element" => 'vc_row',
  1348. "params" => array(
  1349. array(
  1350. "type" => "textfield",
  1351. "holder" => "div",
  1352. "class" => "",
  1353. "heading" => "ID",
  1354. "param_name" => "id",
  1355. "description" => ""
  1356. ),
  1357. array(
  1358. "type" => "textfield",
  1359. "holder" => "div",
  1360. "class" => "",
  1361. "heading" => "SKU",
  1362. "param_name" => "sku",
  1363. "description" => ""
  1364. )
  1365. )
  1366. ) );
  1367.  
  1368. /*** Product by SKU/ID ***/
  1369.  
  1370. vc_map( array(
  1371. "name" => "Product by SKU/ID",
  1372. "base" => "product",
  1373. "icon" => "icon-wpb-product",
  1374. "category" => 'Woocommerce',
  1375. "allowed_container_element" => 'vc_row',
  1376. "params" => array(
  1377. array(
  1378. "type" => "textfield",
  1379. "holder" => "div",
  1380. "class" => "",
  1381. "heading" => "ID",
  1382. "param_name" => "id",
  1383. "description" => ""
  1384. ),
  1385. array(
  1386. "type" => "textfield",
  1387. "holder" => "div",
  1388. "class" => "",
  1389. "heading" => "SKU",
  1390. "param_name" => "sku",
  1391. "description" => ""
  1392. )
  1393. )
  1394. ) );
  1395.  
  1396.  
  1397. /*** Products by SKU/ID ***/
  1398.  
  1399. vc_map( array(
  1400. "name" => "Products by SKU/ID",
  1401. "base" => "products",
  1402. "icon" => "icon-wpb-products",
  1403. "category" => 'Woocommerce',
  1404. "allowed_container_element" => 'vc_row',
  1405. "params" => array(
  1406. array(
  1407. "type" => "textfield",
  1408. "holder" => "div",
  1409. "class" => "",
  1410. "heading" => "IDS",
  1411. "param_name" => "ids",
  1412. "description" => ""
  1413. ),
  1414. array(
  1415. "type" => "textfield",
  1416. "holder" => "div",
  1417. "class" => "",
  1418. "heading" => "SKUS",
  1419. "param_name" => "skus",
  1420. "description" => ""
  1421. )
  1422. )
  1423. ) );
  1424.  
  1425. /*** Product categories ***/
  1426.  
  1427. vc_map( array(
  1428. "name" => "Product categories",
  1429. "base" => "product_categories",
  1430. "icon" => "icon-wpb-product_categories",
  1431. "category" => 'Woocommerce',
  1432. "allowed_container_element" => 'vc_row',
  1433. "params" => array(
  1434. array(
  1435. "type" => "textfield",
  1436. "holder" => "div",
  1437. "class" => "",
  1438. "heading" => "Number",
  1439. "param_name" => "number",
  1440. "description" => ""
  1441. )
  1442. )
  1443. ) );
  1444.  
  1445. /*** Products by category slug ***/
  1446.  
  1447. vc_map( array(
  1448. "name" => "Products by category slug",
  1449. "base" => "product_category",
  1450. "icon" => "icon-wpb-product_category",
  1451. "category" => 'Woocommerce',
  1452. "allowed_container_element" => 'vc_row',
  1453. "params" => array(
  1454. array(
  1455. "type" => "textfield",
  1456. "holder" => "div",
  1457. "class" => "",
  1458. "heading" => "Category",
  1459. "param_name" => "category",
  1460. "description" => ""
  1461. ),
  1462. array(
  1463. "type" => "textfield",
  1464. "holder" => "div",
  1465. "class" => "",
  1466. "heading" => "Per Page",
  1467. "param_name" => "per_page",
  1468. "value" => "12"
  1469. ),
  1470. array(
  1471. "type" => "textfield",
  1472. "holder" => "div",
  1473. "class" => "",
  1474. "heading" => "Columns",
  1475. "param_name" => "columns",
  1476. "value" => "4"
  1477. ),
  1478. array(
  1479. "type" => "dropdown",
  1480. "holder" => "div",
  1481. "class" => "",
  1482. "heading" => "Order By",
  1483. "param_name" => "order_by",
  1484. "value" => array(
  1485. "Date" => "date",
  1486. "Title" => "title",
  1487. ),
  1488. "description" => ""
  1489. ),
  1490. array(
  1491. "type" => "dropdown",
  1492. "holder" => "div",
  1493. "class" => "",
  1494. "heading" => "Order",
  1495. "param_name" => "order",
  1496. "value" => array(
  1497. "DESC" => "desc",
  1498. "ASC" => "asc"
  1499. ),
  1500. "description" => ""
  1501. )
  1502. )
  1503. ) );
  1504.  
  1505. /*** Recent products ***/
  1506.  
  1507. vc_map( array(
  1508. "name" => "Recent products",
  1509. "base" => "recent_products",
  1510. "icon" => "icon-wpb-recent_products",
  1511. "category" => 'Woocommerce',
  1512. "allowed_container_element" => 'vc_row',
  1513. "params" => array(
  1514. array(
  1515. "type" => "textfield",
  1516. "holder" => "div",
  1517. "class" => "",
  1518. "heading" => "Per Page",
  1519. "param_name" => "per_page",
  1520. "value" => "12"
  1521. ),
  1522. array(
  1523. "type" => "textfield",
  1524. "holder" => "div",
  1525. "class" => "",
  1526. "heading" => "Columns",
  1527. "param_name" => "columns",
  1528. "value" => "4"
  1529. ),
  1530. array(
  1531. "type" => "dropdown",
  1532. "holder" => "div",
  1533. "class" => "",
  1534. "heading" => "Order By",
  1535. "param_name" => "order_by",
  1536. "value" => array(
  1537. "Date" => "date",
  1538. "Title" => "title",
  1539. ),
  1540. "description" => ""
  1541. ),
  1542. array(
  1543. "type" => "dropdown",
  1544. "holder" => "div",
  1545. "class" => "",
  1546. "heading" => "Order",
  1547. "param_name" => "order",
  1548. "value" => array(
  1549. "DESC" => "desc",
  1550. "ASC" => "asc"
  1551. ),
  1552. "description" => ""
  1553. ),
  1554. )
  1555. ) );
  1556.  
  1557. /*** Featured products ***/
  1558.  
  1559. vc_map( array(
  1560. "name" => "Featured products",
  1561. "base" => "featured_products",
  1562. "icon" => "icon-wpb-featured_products",
  1563. "category" => 'Woocommerce',
  1564. "allowed_container_element" => 'vc_row',
  1565. "params" => array(
  1566. array(
  1567. "type" => "textfield",
  1568. "holder" => "div",
  1569. "class" => "",
  1570. "heading" => "Per Page",
  1571. "param_name" => "per_page",
  1572. "value" => "12"
  1573. ),
  1574. array(
  1575. "type" => "textfield",
  1576. "holder" => "div",
  1577. "class" => "",
  1578. "heading" => "Columns",
  1579. "param_name" => "columns",
  1580. "value" => "4"
  1581. ),
  1582. array(
  1583. "type" => "dropdown",
  1584. "holder" => "div",
  1585. "class" => "",
  1586. "heading" => "Order By",
  1587. "param_name" => "orderby",
  1588. "value" => array(
  1589. "Date" => "date",
  1590. "Title" => "title",
  1591. ),
  1592. "description" => ""
  1593. ),
  1594. array(
  1595. "type" => "dropdown",
  1596. "holder" => "div",
  1597. "class" => "",
  1598. "heading" => "Order",
  1599. "param_name" => "order",
  1600. "value" => array(
  1601. "DESC" => "desc",
  1602. "ASC" => "asc"
  1603. ),
  1604. "description" => ""
  1605. ),
  1606. )
  1607. ) );
  1608.  
  1609. /**** Shop Messages ***/
  1610.  
  1611. vc_map( array(
  1612. "name" => "Shop Messages",
  1613. "base" => "woocommerce_messages",
  1614. "icon" => "icon-wpb-woocommerce_messages",
  1615. "category" => 'Woocommerce',
  1616. "allowed_container_element" => 'vc_row',
  1617. "show_settings_on_create" => false
  1618. ) );
  1619.  
  1620. }
  1621.  
  1622. /***************************************************
  1623. * :: WooCommerce My Account Buddypress Integration
  1624. ***************************************************/
  1625.  
  1626. if ( function_exists( 'bp_is_active' ) && is_user_logged_in() && sq_option( 'woo_buddypress_menus', 1 ) == 1 ) {
  1627. // Add the Orders tab to BuddyPress profile
  1628. add_action( 'bp_setup_nav', 'kleo_woo_profile_nav_orders', 301 );
  1629. function kleo_woo_profile_nav_orders() {
  1630. $bp = buddypress();
  1631. bp_core_new_nav_item(
  1632. array(
  1633. 'name' => __( 'Orders', 'woocommerce' ),
  1634. 'slug' => 'orders',
  1635. 'position' => 21,
  1636. 'show_for_displayed_user' => false,
  1637. 'screen_function' => 'bp_woo_orders_screen',
  1638. 'default_subnav_slug' => 'my-orders',
  1639. ) );
  1640. }
  1641.  
  1642. // Add submenus to Orders tab
  1643. add_action( 'bp_setup_nav', 'kleo_woo_order_submenus', 302 );
  1644. function kleo_woo_order_submenus() {
  1645. $bp = buddypress();
  1646. if ( version_compare( BP_VERSION, '2.6', '>=' ) ) {
  1647. $url = $bp->members->nav->orders->slug;
  1648. } else {
  1649. $url = $bp->bp_nav['orders']['slug'];
  1650. }
  1651.  
  1652.  
  1653. bp_core_new_subnav_item(
  1654. array(
  1655. 'name' => __( 'My Orders', 'kleo_framework' ),
  1656. 'slug' => 'my-orders',
  1657. 'parent_url' => $bp->loggedin_user->domain . $url . '/',
  1658. 'parent_slug' => $url,
  1659. 'position' => 10,
  1660. 'show_for_displayed_user' => false,
  1661. 'screen_function' => 'kleo_woo_orders_screen',
  1662. ) );
  1663.  
  1664. bp_core_new_subnav_item(
  1665. array(
  1666. 'name' => __( 'My Downloads', 'kleo_framework' ),
  1667. 'slug' => 'downloads',
  1668. 'parent_url' => $bp->loggedin_user->domain . $url . '/',
  1669. 'parent_slug' => $url,
  1670. 'position' => 20,
  1671. 'show_for_displayed_user' => false,
  1672. 'screen_function' => 'kleo_woo_downloads_screen'
  1673. ) );
  1674. }
  1675.  
  1676. // Load My Orders template
  1677. function kleo_woo_orders_screen() {
  1678. add_action( 'bp_template_content', 'kleo_woo_orders_screen_content' );
  1679. bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  1680. }
  1681.  
  1682. // Display My Orders screen
  1683. function kleo_woo_orders_screen_content() {
  1684. echo '<div class="woocommerce">';
  1685. wc_get_template( 'myaccount/my-orders.php' );
  1686. echo '</div>';
  1687. }
  1688.  
  1689. // Load My Downloads template
  1690. function kleo_woo_downloads_screen() {
  1691. add_action( 'bp_template_content', 'kleo_woo_downloads_screen_content' );
  1692. bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  1693. }
  1694.  
  1695. // Display My Downloads screen
  1696. function kleo_woo_downloads_screen_content() {
  1697. echo '<div class="woocommerce">';
  1698. wc_get_template( 'myaccount/my-downloads.php' );
  1699. echo '</div>';
  1700. }
  1701.  
  1702. // Add account settings into profile settings
  1703.  
  1704. // Add address sub menu to settings menu
  1705. add_action( 'bp_setup_nav', 'kleo_woo_address_submenu', 302 );
  1706. function kleo_woo_address_submenu() {
  1707. $bp = buddypress();
  1708.  
  1709. if ( version_compare( BP_VERSION, '2.6', '>=' ) ) {
  1710. $url = $bp->members->nav->settings->slug;
  1711. } else {
  1712. $url = $bp->bp_nav['settings']['slug'];
  1713. }
  1714.  
  1715. bp_core_new_subnav_item(
  1716. array(
  1717. 'name' => __( 'My Addresses', 'woocommerce' ),
  1718. 'slug' => 'my-address',
  1719. 'parent_url' => $bp->loggedin_user->domain . $url . '/',
  1720. 'parent_slug' => $url,
  1721. 'position' => 15,
  1722. 'show_for_displayed_user' => false,
  1723. 'screen_function' => 'kleo_woo_address_screen',
  1724. ) );
  1725. }
  1726.  
  1727. // Load address template
  1728. function kleo_woo_address_screen() {
  1729. add_action( 'bp_template_content', 'kleo_woo_address_screen_content' );
  1730. bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  1731. }
  1732.  
  1733. // Load address screen
  1734. function kleo_woo_address_screen_content() {
  1735. echo '<div class="woocommerce">';
  1736.  
  1737. wc_get_template( 'myaccount/form-edit-address.php', array(
  1738. 'load_address' => ''
  1739. ) );
  1740. echo '</div>';
  1741. }
  1742.  
  1743. //Remove Settings > General screen and replace with woo account edit screen
  1744. //add_action( 'bp_setup_nav', 'kleo_remove_general_settings' , 301 );
  1745. function kleo_remove_general_settings() {
  1746. bp_core_remove_subnav_item( 'settings', 'general' );
  1747. }
  1748.  
  1749. //Change default subnav for settings
  1750. //add_action('bp_setup_nav', 'kleo_change_settings_subnav', 5);
  1751. function kleo_change_settings_subnav() {
  1752. $args = array(
  1753. 'parent_slug' => 'settings',
  1754. 'screen_function' => 'bp_woo_edit_account_screen',
  1755. 'subnav_slug' => 'account'
  1756. );
  1757. bp_core_new_nav_default( $args );
  1758. }
  1759.  
  1760. // Add edit account sub menu
  1761. //add_action( 'bp_setup_nav', 'kleo_woo_edit_account_submenu' , 302 );
  1762. function kleo_woo_edit_account_submenu() {
  1763. global $bp;
  1764. bp_core_new_subnav_item(
  1765. array(
  1766. 'name' => __( 'Account', 'kleo_framework' ),
  1767. 'slug' => 'account',
  1768. 'parent_url' => $bp->loggedin_user->domain . $bp->bp_nav['settings']['slug'] . '/',
  1769. 'parent_slug' => $bp->bp_nav['settings']['slug'],
  1770. 'position' => 10,
  1771. 'show_for_displayed_user' => false,
  1772. 'screen_function' => 'kleo_woo_edit_account_screen',
  1773. ) );
  1774. }
  1775.  
  1776. // Load account template
  1777. function kleo_woo_edit_account_screen() {
  1778. add_action( 'bp_template_content', 'kleo_woo_edit_account_screen_content' );
  1779. bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  1780. }
  1781.  
  1782. // Display edit account screen
  1783. function kleo_woo_edit_account_screen_content() {
  1784. echo '<div class="woocommerce">';
  1785. wc_get_template( 'myaccount/form-edit-account.php', array( 'user' => get_user_by( 'id', get_current_user_id() ) ) );
  1786. echo '</div>';
  1787.  
  1788. }
  1789.  
  1790. // Make sure we stay in Buddypress profile after edits
  1791. add_action( 'woocommerce_customer_save_address', 'kleo_save_address_bp_redirect' );
  1792. function kleo_save_address_bp_redirect() {
  1793. global $bp;
  1794. wp_safe_redirect( $bp->loggedin_user->domain . $bp->settings->slug . '/my-address/' );
  1795. exit;
  1796. }
  1797.  
  1798. //add_action( 'woocommerce_save_account_details', 'kleo_save_account_bp_redirect' );
  1799. function kleo_save_account_bp_redirect() {
  1800. global $bp;
  1801. wp_safe_redirect( $bp->loggedin_user->domain . $bp->settings->slug . '/account/' );
  1802. exit;
  1803. }
  1804.  
  1805. // Add button on order detail screen to return to order list
  1806. add_action( 'woocommerce_view_order', 'kleo_return_to_bp_order_list' );
  1807. function kleo_return_to_bp_order_list() { ?>
  1808. <?php global $bp; ?>
  1809. <a href="<?php echo $bp->loggedin_user->domain . 'orders/'; ?>"
  1810. title="<?php _e( 'View All Orders', 'kleo_framework' ); ?>"
  1811. class="button"><?php _e( 'View All Orders', 'kleo_framework' ); ?></a>
  1812. <?php }
  1813.  
  1814. } else {
  1815.  
  1816. // Add button on order detail screen to return to order list
  1817. add_action( 'woocommerce_view_order', 'kleo_return_to_wc_order_list' );
  1818. function kleo_return_to_wc_order_list() { ?>
  1819. <a href="<?php echo get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ); ?>"
  1820. title="<?php _e( 'View All Orders', 'kleo_framework' ); ?>"
  1821. class="button"><?php _e( 'My Account', 'kleo_framework' ); ?></a>
  1822. <?php
  1823. }
  1824. }
  1825.  
  1826.  
  1827. /* Compatibility with Woocommerce < 2.4 */
  1828. if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
  1829.  
  1830. /**
  1831. * Output a list of variation attributes for use in the cart forms.
  1832. *
  1833. * @param array $args
  1834. *
  1835. * @since 2.4.0
  1836. */
  1837. function wc_dropdown_variation_attribute_options( $args = array() ) {
  1838. $args = wp_parse_args( apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ), array(
  1839. 'options' => false,
  1840. 'attribute' => false,
  1841. 'product' => false,
  1842. 'selected' => false,
  1843. 'name' => '',
  1844. 'id' => '',
  1845. 'class' => '',
  1846. 'show_option_none' => __( 'Choose an option', 'woocommerce' ),
  1847. ) );
  1848.  
  1849. $options = $args['options'];
  1850. $product = $args['product'];
  1851. $attribute = $args['attribute'];
  1852. $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
  1853. $id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
  1854. $class = $args['class'];
  1855. $show_option_none = $args['show_option_none'] ? true : false;
  1856. $show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' ); // We'll do our best to hide the placeholder, but we'll need to show something when resetting options.
  1857.  
  1858. if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
  1859. $attributes = $product->get_variation_attributes();
  1860. $options = $attributes[ $attribute ];
  1861. }
  1862.  
  1863. $html = '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
  1864. $html .= '<option value="">' . esc_html( $show_option_none_text ) . '</option>';
  1865.  
  1866. if ( ! empty( $options ) ) {
  1867. if ( $product && taxonomy_exists( $attribute ) ) {
  1868. // Get terms if this is a taxonomy - ordered. We need the names too.
  1869. $terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
  1870.  
  1871. foreach ( $terms as $term ) {
  1872. if ( in_array( $term->slug, $options ) ) {
  1873. $html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
  1874. }
  1875. }
  1876. } else {
  1877. foreach ( $options as $option ) {
  1878. // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
  1879. $selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
  1880. $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
  1881. }
  1882. }
  1883. }
  1884.  
  1885. $html .= '</select>';
  1886.  
  1887. echo apply_filters( 'woocommerce_dropdown_variation_attribute_options_html', $html, $args );
  1888. }
  1889. }
  1890.  
  1891.  
  1892. if ( ! function_exists( 'woocommerce_single_variation' ) ) {
  1893.  
  1894. add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
  1895.  
  1896. /**
  1897. * Output placeholders for the single variation.
  1898. */
  1899. function woocommerce_single_variation() {
  1900. echo '<div class="single_variation"></div>';
  1901. }
  1902. }
  1903.  
  1904. if ( ! function_exists( 'woocommerce_single_variation_add_to_cart_button' ) ) {
  1905.  
  1906. /**
  1907. * Output the add to cart button for variations.
  1908. */
  1909. function woocommerce_single_variation_add_to_cart_button() {
  1910. wc_get_template( 'single-product/add-to-cart/variation-add-to-cart-button.php' );
  1911. }
  1912. }
  1913.  
  1914. if ( ! function_exists( 'wc_get_stock_html' ) ) {
  1915. /**
  1916. * Get HTML to show product stock.
  1917. * @since 3.0.0
  1918. *
  1919. * @param WC_Product $product
  1920. *
  1921. * @return string
  1922. */
  1923. function wc_get_stock_html( $product ) {
  1924.  
  1925. $html = '';
  1926. $availability = $product->get_availability();
  1927.  
  1928. if ( ! empty( $availability['availability'] ) ) {
  1929. ob_start();
  1930.  
  1931. wc_get_template( 'single-product/stock.php', array(
  1932. 'product' => $product,
  1933. 'class' => $availability['class'],
  1934. 'availability' => $availability['availability'],
  1935. ) );
  1936.  
  1937. $html = ob_get_clean();
  1938. }
  1939.  
  1940. if ( has_filter( 'woocommerce_stock_html' ) ) {
  1941. wc_deprecated_function( 'The woocommerce_stock_html filter', '', 'woocommerce_get_stock_html' );
  1942. $html = apply_filters( 'woocommerce_stock_html', $html, $availability['availability'], $product );
  1943. }
  1944.  
  1945. return apply_filters( 'woocommerce_get_stock_html', $html, $product );
  1946. }
  1947. }
  1948.  
  1949. function kleo_title_args_singular_product( $args ) {
  1950. if ( is_singular( 'product' ) ) {
  1951. $args['heading'] = 'span';
  1952. }
  1953.  
  1954. return $args;
  1955. }
  1956.  
  1957. add_filter( 'kleo_title_args', 'kleo_title_args_singular_product' );
  1958.  
  1959. /* Trigger the reviews tab when clicking on the reviews starts */
  1960. function kleo_woocommerce_wp_footer() {
  1961. if ( is_singular( 'product' ) ) {
  1962. echo '<script>jQuery(document).ready(function(){ jQuery(\'a[href="#reviews"]\').on("click", function(){ jQuery(\'a[href="#reviews_tab"]\').trigger("click"); return false; }); });</script>';
  1963. }
  1964. }
  1965.  
  1966. add_action( 'wp_footer', 'kleo_woocommerce_wp_footer' );
  1967.  
  1968.  
  1969. /* Remove product loop link wrapper */
  1970. remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
  1971. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
  1972.  
  1973.  
  1974. /* Srcset fix for variations */
  1975. add_filter( 'woocommerce_available_variation', 'sq_remove_img_srcset_variations' );
  1976.  
  1977. function sq_remove_img_srcset_variations( $attr ) {
  1978. if ( ! empty( $attr ) ) {
  1979. unset( $attr['image_srcset'] );
  1980. unset( $attr['image_sizes'] );
  1981. }
  1982.  
  1983. return $attr;
  1984. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement