PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/vantagechild-harpar/inc/general_functions.php

https://gitlab.com/haque.mdmanzurul/wp-harpar-carolyn
PHP | 269 lines | 209 code | 37 blank | 23 comment | 22 complexity | 464f8d798e8ee7a69ff48fe275cb721f MD5 | raw file
  1. <?php
  2. /* Removing Tabs*/
  3. add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
  4. function woo_remove_product_tabs( $tabs ) {
  5. unset( $tabs['description'] ); // Remove the description tab
  6. unset( $tabs['reviews'] ); // Remove the reviews tab
  7. return $tabs;
  8. }
  9. /*Adding Custom Tab*/
  10. add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
  11. function woo_new_product_tab( $tabs ) {
  12. // Adds the new tab
  13. $tabs['course_info'] = array(
  14. 'title' => __( 'Course Info', 'woocommerce' ),
  15. 'priority' => 50,
  16. 'callback' => 'woo_new_product_tab_content_course_info'
  17. );
  18. $tabs['modules'] = array(
  19. 'title' => __( 'Modules', 'woocommerce' ),
  20. 'priority' => 55,
  21. 'callback' => 'woo_new_product_tab_content_modules'
  22. );
  23. $tabs['assesment_criteria'] = array(
  24. 'title' => __( 'How you are assesed', 'woocommerce' ),
  25. 'priority' => 60,
  26. 'callback' => 'woo_new_product_tab_content_assesment'
  27. );
  28. return $tabs;
  29. }
  30. //Course info Tab data
  31. function woo_new_product_tab_content_course_info() {
  32. // The new tab content
  33. echo the_field('course_info');
  34. }
  35. //Modules Tabs
  36. function woo_new_product_tab_content_modules() {
  37. // The new tab content
  38. echo the_field('modules');
  39. }
  40. //Assesment tab
  41. function woo_new_product_tab_content_assesment() {
  42. // The new tab content
  43. echo the_field('assesment');
  44. }
  45. //Remove Product Page sidebar
  46. add_action('template_redirect', 'remove_sidebar_shop');
  47. function remove_sidebar_shop() {
  48. if ( is_singular('product') ) {
  49. remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar');
  50. }
  51. }
  52. /*
  53. * wc_remove_related_products
  54. *
  55. * Clear the query arguments for related products so none show.
  56. * Add this code to your theme functions.php file.
  57. */
  58. function wc_remove_related_products( $args ) {
  59. return array();
  60. }
  61. add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);
  62. //get rpoduct taxonomies
  63. function get_woo_taxonomies($taxonomy = 'joblevels', $start_title = "Select a Job Level"){
  64. $output = "<select name=\"$taxonomy\" class=\"turnintodropdown\"><option>$start_title</option>";
  65. $orderby = 'name';
  66. $show_count = 1; // 1 for yes, 0 for no
  67. $pad_counts = 1; // 1 for yes, 0 for no
  68. $hierarchical = 1; // 1 for yes, 0 for no
  69. $title = '';
  70. $empty = 0;
  71. $args = array(
  72. 'taxonomy' => $taxonomy,
  73. 'orderby' => $orderby,
  74. 'show_count' => $show_count,
  75. 'pad_counts' => $pad_counts,
  76. 'hierarchical' => $hierarchical,
  77. 'title_li' => $title,
  78. 'hide_empty' => $empty
  79. );
  80. $all_categories = get_categories( $args );
  81. foreach ($all_categories as $cat) {
  82. if($cat->category_parent == 0) {
  83. $category_id = $cat->term_id;
  84. $output .='<option value="'.$cat->term_id.'"><a href="#">'. $cat->name .'</a></li>';
  85. }
  86. }
  87. $output .='</select>';
  88. return $output;
  89. }
  90. /* Get Woo-commerce Product*/
  91. function get_products($atts){
  92. $a = shortcode_atts( array(
  93. 'cats' =>'',
  94. 'qualifications' => '',
  95. 'joblevels' => '',
  96. 'display_title'=>'courses'
  97. ), $atts );
  98. global $paged;
  99. $curpage = $paged ? $paged : 1;
  100. $tax_query = array('relation' => 'AND');
  101. $cat = isset($_REQUEST['product_cat'])&&is_numeric($_REQUEST['product_cat'])?$_REQUEST['product_cat']:'';
  102. if($cat!=''){
  103. array_push($tax_query,array(
  104. 'taxonomy' => 'product_cat',
  105. 'field' => 'term_id',
  106. 'terms' => $cat
  107. ));
  108. }else if($a['cats']!=""){
  109. array_push($tax_query,array(
  110. 'taxonomy' => 'product_cat',
  111. 'field' => 'term_id',
  112. 'terms' => explode(",",$a['cats'])
  113. ));
  114. }
  115. $joblevel = isset($_REQUEST['joblevels'])&&is_numeric($_REQUEST['joblevels'])?$_REQUEST['joblevels']:'';
  116. if($joblevel!=''){
  117. array_push($tax_query,array(
  118. 'taxonomy' => 'joblevels',
  119. 'field' => 'term_id',
  120. 'terms' => $joblevel
  121. ));
  122. }else if($a['joblevels']!=""){
  123. array_push($tax_query,array(
  124. 'taxonomy' => 'joblevels',
  125. 'field' => 'term_id',
  126. 'terms' => explode(",",$a['joblevels'])
  127. ));
  128. }
  129. $qualifications = isset($_REQUEST['qualifications'])&&is_numeric($_REQUEST['qualifications'])?$_REQUEST['qualifications']:'';
  130. if($qualifications!=''){
  131. array_push($tax_query,array(
  132. 'taxonomy' => 'qualifications',
  133. 'field' => 'term_id',
  134. 'terms' => $qualifications
  135. ));
  136. }else if($a['qualifications']!=""){
  137. array_push($tax_query,array(
  138. 'taxonomy' => 'qualifications',
  139. 'field' => 'term_id',
  140. 'terms' => explode(",",$a['qualifications'])
  141. ));
  142. }
  143. $page = get_query_var( 'page' );
  144. $args = array(
  145. 'posts_per_page' => 4,
  146. 'post_type' => 'product',
  147. 'orderby' => 'title',
  148. 'paged'=>$paged
  149. );
  150. if(count($tax_query)!=0)
  151. $args['tax_query'] = $tax_query;
  152. $myquery = new WP_Query($args);
  153. ob_start();
  154. ?>
  155. <?php
  156. if ( $myquery->have_posts() ) :
  157. ?>
  158. <div class="itemcount">Displaying <?php if($myquery->found_posts<4) echo $myquery->found_posts; else if($myquery->found_posts<$args['paged']*4) echo $myquery->found_posts; else if($args['paged']==0) echo 4; else echo $args['paged']*4; ?> of <?php echo $myquery->found_posts; ?> <?php echo ($a['display_title']=="" OR $a['display_title']=="courses")?"courses":"ebooks" ?></div>
  159. <ul class="products custom-search">
  160. <?php
  161. while ( $myquery->have_posts() ) : $myquery->the_post(); global $product;
  162. ?>
  163. <li>
  164. <div class="product_image">
  165. <?php
  166. //display product thumbnail
  167. if (has_post_thumbnail()) {
  168. $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'thumbnail' );
  169. echo '<img src="' . $image_src[0] . '" width="140" alt="" />';
  170. }
  171. else {
  172. echo '<img src="/images/defaul_image.jpg" width="140" alt=" />';
  173. }
  174. ?>
  175. </div>
  176. <div class="product_description">
  177. <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  178. <?php the_excerpt();
  179. $price = get_post_meta( get_the_ID(), '_regular_price', true); ?>
  180. <div class="product-price"><span class="price">Price</span><span class="price-digit"><?php echo get_woocommerce_currency_symbol().' '.$price ?></span></div>
  181. <div class="product-meta">
  182. <a href="<?php the_permalink()?>" class="find-out-more" style="background-color:<?php echo get_field('readmore_buttom_background') ?>">Find out more</a>
  183. <a class="add_to_cart_button product_type_simple" style="background-color:<?php echo get_field('readmore_buttom_background') ?>" data-quantity="1" data-product_sku="<?php echo $product->get_sku(); ?>" data-product_id="<?php the_ID(); ?>" rel="nofollow" href="/course-finder/?add-to-cart=23">Buy Now</a>
  184. </div>
  185. </div>
  186. </li>
  187. <?php
  188. endwhile; ?></ul>
  189. <?php
  190. wp_paginate($myquery);
  191. echo '
  192. <div class="navigation"><ol class="wp-paginate">
  193. <li><a class="first page" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">&laquo;</a></li>';
  194. for($i=1;$i<=$myquery->max_num_pages;$i++)
  195. echo '<li><a class="'.($i == $curpage ? 'current ' : '').'page" href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
  196. echo '
  197. <!-- <li><a class="page" href="'.get_pagenum_link(($curpage+1 <= $myquery->max_num_pages ? $curpage+1 : $myquery->max_num_pages)).'">&raquo;</a></li>--></ol>
  198. </div>
  199. ';
  200. else:
  201. ?>
  202. <p>No Course found. Please search again</p>
  203. <?php
  204. endif;
  205. $html = ob_get_clean();
  206. return $html;
  207. }
  208. add_shortcode('woocommerce_products','get_products');
  209. /**
  210. * Add view button to product in best seeler tab
  211. *
  212. */
  213. function add_view_button_to_home_products(){
  214. echo '<span class="view-product" style="background-color:'.get_field('readmore_buttom_background').'">View</span>';
  215. }
  216. add_action('woocommerce_before_shop_loop_item_title','add_view_button_to_home_products');
  217. function vantage_metaslider_product_setting_metabox(){
  218. add_meta_box('vantage-metaslider-page-slider', __('Page Meta Slider', 'vantage'), 'vantage_metaslider_page_setting_metabox_render', 'product', 'side');
  219. }
  220. add_action('add_meta_boxes', 'vantage_metaslider_product_setting_metabox');
  221. function woo_mini_cart_custom(){
  222. global $woocommerce;
  223. $output = "";
  224. ob_start();
  225. ?>
  226. <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item in the basket', '%d items in the basket', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a>
  227. <?php
  228. $output = ob_get_clean();
  229. return $output;
  230. }
  231. add_shortcode("woo-custom-mini-cart","woo_mini_cart_custom");
  232. ?>