Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.94 KB | None | 0 0
  1. <?php
  2. /**
  3. * Twenty Twelve functions and definitions.
  4. *
  5. * Sets up the theme and provides some helper functions, which are used
  6. * in the theme as custom template tags. Others are attached to action and
  7. * filter hooks in WordPress to change core functionality.
  8. *
  9. * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  10. * http://codex.wordpress.org/Child_Themes), you can override certain functions
  11. * (those wrapped in a function_exists() call) by defining them first in your child theme's
  12. * functions.php file. The child theme's functions.php file is included before the parent
  13. * theme's file, so the child theme functions would be used.
  14. *
  15. * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  16. * to a filter or action hook.
  17. *
  18. * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  19. *
  20. * @package WordPress
  21. * @subpackage Twenty_Twelve
  22. * @since Twenty Twelve 1.0
  23. */
  24.  
  25.  
  26.  
  27.  
  28. /**
  29. * Sets up the content width value based on the theme's design and stylesheet.
  30. */
  31. if ( ! isset( $content_width ) )
  32. $content_width = 625;
  33.  
  34. /**
  35. * Sets up theme defaults and registers the various WordPress features that
  36. * Twenty Twelve supports.
  37. *
  38. * @uses load_theme_textdomain() For translation/localization support.
  39. * @uses add_editor_style() To add a Visual Editor stylesheet.
  40. * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
  41. * custom background, and post formats.
  42. * @uses register_nav_menu() To add support for navigation menus.
  43. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  44. *
  45. * @since Twenty Twelve 1.0
  46. */
  47. function twentytwelve_setup() {
  48. /*
  49. * Makes Twenty Twelve available for translation.
  50. *
  51. * Translations can be added to the /languages/ directory.
  52. * If you're building a theme based on Twenty Twelve, use a find and replace
  53. * to change 'twentytwelve' to the name of your theme in all the template files.
  54. */
  55. load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
  56.  
  57. // This theme styles the visual editor with editor-style.css to match the theme style.
  58. add_editor_style();
  59.  
  60. // Adds RSS feed links to <head> for posts and comments.
  61. add_theme_support( 'automatic-feed-links' );
  62.  
  63. add_theme_support( 'woocommerce' );
  64.  
  65. // This theme supports a variety of post formats.
  66. add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
  67.  
  68. // This theme uses wp_nav_menu() in one location.
  69. register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
  70. register_nav_menu( 'footernav', __( 'Footer Menu', 'twentytwelve' ) );
  71.  
  72. /*
  73. * This theme supports custom background color and image, and here
  74. * we also set up the default background color.
  75. */
  76. add_theme_support( 'custom-background', array(
  77. 'default-color' => 'e6e6e6',
  78. ) );
  79.  
  80. // This theme uses a custom image size for featured images, displayed on "standard" posts.
  81. add_theme_support( 'post-thumbnails' );
  82. set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop
  83. add_image_size("front-top-feature-thumb",300,300, true);
  84. }
  85. add_action( 'after_setup_theme', 'twentytwelve_setup' );
  86.  
  87. /**
  88. * Adds support for a custom header image.
  89. */
  90. //require( get_template_directory() . '/inc/custom-header.php' );
  91.  
  92. /**
  93. * Enqueues scripts and styles for front-end.
  94. *
  95. * @since Twenty Twelve 1.0
  96. */
  97. function twentytwelve_scripts_styles() {
  98. global $wp_styles;
  99.  
  100. /*
  101. * Adds JavaScript to pages with the comment form to support
  102. * sites with threaded comments (when in use).
  103. */
  104. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
  105. wp_enqueue_script( 'comment-reply' );
  106.  
  107. /*
  108. * Adds JavaScript for handling the navigation menu hide-and-show behavior.
  109. */
  110. wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
  111. wp_enqueue_style( 'magnific-popup-stylesheet', get_template_directory_uri() . '/css/magnific-popup.css', array(), null );
  112. wp_enqueue_script( 'magnific-popup-script', get_template_directory_uri() . '/js/jquery.magnific-popup.min.js', array('jquery'), '1.5.25', true );
  113. /*
  114. * Loads our special font CSS file.
  115. *
  116. * The use of Open Sans by default is localized. For languages that use
  117. * characters not supported by the font, the font can be disabled.
  118. *
  119. * To disable in a child theme, use wp_dequeue_style()
  120. * function mytheme_dequeue_fonts() {
  121. * wp_dequeue_style( 'twentytwelve-fonts' );
  122. * }
  123. * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
  124. */
  125.  
  126. /* translators: If there are characters in your language that are not supported
  127. by Open Sans, translate this to 'off'. Do not translate into your own language. */
  128. if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
  129. $subsets = 'latin,latin-ext';
  130.  
  131. /* translators: To add an additional Open Sans character subset specific to your language, translate
  132. this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
  133. $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
  134.  
  135. if ( 'cyrillic' == $subset )
  136. $subsets .= ',cyrillic,cyrillic-ext';
  137. elseif ( 'greek' == $subset )
  138. $subsets .= ',greek,greek-ext';
  139. elseif ( 'vietnamese' == $subset )
  140. $subsets .= ',vietnamese';
  141.  
  142. $protocol = is_ssl() ? 'https' : 'http';
  143. $query_args = array(
  144. 'family' => 'Open+Sans:400italic,700italic,400,700',
  145. 'subset' => $subsets,
  146. );
  147. wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );
  148. }
  149.  
  150. /*
  151. * Loads our main stylesheet.
  152. */
  153. wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
  154. wp_enqueue_script( 'main-script', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0.0', true );
  155. /*
  156. * Loads the Internet Explorer specific stylesheet.
  157. */
  158. wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
  159. $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
  160. }
  161. add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
  162.  
  163. /**
  164. * Creates a nicely formatted and more specific title element text
  165. * for output in head of document, based on current view.
  166. *
  167. * @since Twenty Twelve 1.0
  168. *
  169. * @param string $title Default title text for current view.
  170. * @param string $sep Optional separator.
  171. * @return string Filtered title.
  172. */
  173. function twentytwelve_wp_title( $title, $sep ) {
  174. global $paged, $page;
  175.  
  176. if ( is_feed() )
  177. return $title;
  178.  
  179. // Add the site name.
  180. $title .= get_bloginfo( 'name' );
  181.  
  182. // Add the site description for the home/front page.
  183. $site_description = get_bloginfo( 'description', 'display' );
  184. if ( $site_description && ( is_home() || is_front_page() ) )
  185. $title = "$title $sep $site_description";
  186.  
  187. // Add a page number if necessary.
  188. if ( $paged >= 2 || $page >= 2 )
  189. $title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
  190.  
  191. return $title;
  192. }
  193. add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
  194.  
  195. /**
  196. * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
  197. *
  198. * @since Twenty Twelve 1.0
  199. */
  200. function twentytwelve_page_menu_args( $args ) {
  201. if ( ! isset( $args['show_home'] ) )
  202. $args['show_home'] = true;
  203. return $args;
  204. }
  205. add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' );
  206.  
  207. /**
  208. * Registers our main widget area and the front page widget areas.
  209. *
  210. * @since Twenty Twelve 1.0
  211. */
  212. function twentytwelve_widgets_init() {
  213. register_sidebar( array(
  214. 'name' => __( 'Main Sidebar', 'twentytwelve' ),
  215. 'id' => 'sidebar-1',
  216. 'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
  217. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  218. 'after_widget' => '</aside>',
  219. 'before_title' => '<h3 class="widget-title">',
  220. 'after_title' => '</h3>',
  221. ) );
  222.  
  223. register_sidebar( array(
  224. 'name' => __( 'First Front Page Widget Area', 'twentytwelve' ),
  225. 'id' => 'sidebar-2',
  226. 'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
  227. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  228. 'after_widget' => '</aside>',
  229. 'before_title' => '<h3 class="widget-title">',
  230. 'after_title' => '</h3>',
  231. ) );
  232.  
  233. register_sidebar( array(
  234. 'name' => __( 'Second Front Page Widget Area', 'twentytwelve' ),
  235. 'id' => 'sidebar-3',
  236. 'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
  237. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  238. 'after_widget' => '</aside>',
  239. 'before_title' => '<h3 class="widget-title">',
  240. 'after_title' => '</h3>',
  241. ) );
  242.  
  243. register_sidebar( array(
  244. 'name' => __( 'Shop Page Widget Area', 'twentytwelve' ),
  245. 'id' => 'sidebar-4',
  246. 'description' => __( 'Shop Page Widget Area', 'twentytwelve' ),
  247. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  248. 'after_widget' => '</aside>',
  249. 'before_title' => '<h3 class="widget-title">',
  250. 'after_title' => '</h3>',
  251. ) );
  252. }
  253. add_action( 'widgets_init', 'twentytwelve_widgets_init' );
  254.  
  255. if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
  256. /**
  257. * Displays navigation to next/previous pages when applicable.
  258. *
  259. * @since Twenty Twelve 1.0
  260. */
  261. function twentytwelve_content_nav( $html_id ) {
  262. global $wp_query;
  263.  
  264. $html_id = esc_attr( $html_id );
  265.  
  266. if ( $wp_query->max_num_pages > 1 ) : ?>
  267. <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
  268. <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
  269. <div class="nav-previous alignleft"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
  270. <div class="nav-next alignright"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
  271. </nav><!-- #<?php echo $html_id; ?> .navigation -->
  272. <?php endif;
  273. }
  274. endif;
  275.  
  276. if ( ! function_exists( 'twentytwelve_comment' ) ) :
  277. /**
  278. * Template for comments and pingbacks.
  279. *
  280. * To override this walker in a child theme without modifying the comments template
  281. * simply create your own twentytwelve_comment(), and that function will be used instead.
  282. *
  283. * Used as a callback by wp_list_comments() for displaying the comments.
  284. *
  285. * @since Twenty Twelve 1.0
  286. */
  287. function twentytwelve_comment( $comment, $args, $depth ) {
  288. $GLOBALS['comment'] = $comment;
  289. switch ( $comment->comment_type ) :
  290. case 'pingback' :
  291. case 'trackback' :
  292. // Display trackbacks differently than normal comments.
  293. ?>
  294. <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  295. <p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
  296. <?php
  297. break;
  298. default :
  299. // Proceed with normal comments.
  300. global $post;
  301. ?>
  302. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  303. <article id="comment-<?php comment_ID(); ?>" class="comment">
  304. <header class="comment-meta comment-author vcard">
  305. <?php
  306. echo get_avatar( $comment, 44 );
  307. printf( '<cite class="fn">%1$s %2$s</cite>',
  308. get_comment_author_link(),
  309. // If current post author is also comment author, make it known visually.
  310. ( $comment->user_id === $post->post_author ) ? '<span> ' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
  311. );
  312. printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
  313. esc_url( get_comment_link( $comment->comment_ID ) ),
  314. get_comment_time( 'c' ),
  315. /* translators: 1: date, 2: time */
  316. sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
  317. );
  318. ?>
  319. </header><!-- .comment-meta -->
  320.  
  321. <?php if ( '0' == $comment->comment_approved ) : ?>
  322. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
  323. <?php endif; ?>
  324.  
  325. <section class="comment-content comment">
  326. <?php comment_text(); ?>
  327. <?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
  328. </section><!-- .comment-content -->
  329.  
  330. <div class="reply">
  331. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  332. </div><!-- .reply -->
  333. </article><!-- #comment-## -->
  334. <?php
  335. break;
  336. endswitch; // end comment_type check
  337. }
  338. endif;
  339.  
  340. if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
  341. /**
  342. * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
  343. *
  344. * Create your own twentytwelve_entry_meta() to override in a child theme.
  345. *
  346. * @since Twenty Twelve 1.0
  347. */
  348. function twentytwelve_entry_meta() {
  349. // Translators: used between list items, there is a space after the comma.
  350. $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
  351.  
  352. // Translators: used between list items, there is a space after the comma.
  353. $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
  354.  
  355. $date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
  356. esc_url( get_permalink() ),
  357. esc_attr( get_the_time() ),
  358. esc_attr( get_the_date( 'c' ) ),
  359. esc_html( get_the_date() )
  360. );
  361.  
  362. $author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
  363. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  364. esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
  365. get_the_author()
  366. );
  367.  
  368. // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
  369. if ( $tag_list ) {
  370. $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
  371. } elseif ( $categories_list ) {
  372. $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
  373. } else {
  374. $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
  375. }
  376.  
  377. printf(
  378. $utility_text,
  379. $categories_list,
  380. $tag_list,
  381. $date,
  382. $author
  383. );
  384. }
  385. endif;
  386.  
  387. /**
  388. * Extends the default WordPress body class to denote:
  389. * 1. Using a full-width layout, when no active widgets in the sidebar
  390. * or full-width template.
  391. * 2. Front Page template: thumbnail in use and number of sidebars for
  392. * widget areas.
  393. * 3. White or empty background color to change the layout and spacing.
  394. * 4. Custom fonts enabled.
  395. * 5. Single or multiple authors.
  396. *
  397. * @since Twenty Twelve 1.0
  398. *
  399. * @param array Existing class values.
  400. * @return array Filtered class values.
  401. */
  402. function twentytwelve_body_class( $classes ) {
  403. $background_color = get_background_color();
  404.  
  405. if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) )
  406. $classes[] = 'full-width';
  407.  
  408. if ( is_page_template( 'page-templates/front-page.php' ) ) {
  409. $classes[] = 'template-front-page';
  410. if ( has_post_thumbnail() )
  411. $classes[] = 'has-post-thumbnail';
  412. if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )
  413. $classes[] = 'two-sidebars';
  414. }
  415.  
  416. if ( empty( $background_color ) )
  417. $classes[] = 'custom-background-empty';
  418. elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) )
  419. $classes[] = 'custom-background-white';
  420.  
  421. // Enable custom font class only if the font CSS is queued to load.
  422. if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) )
  423. $classes[] = 'custom-font-enabled';
  424.  
  425. if ( ! is_multi_author() )
  426. $classes[] = 'single-author';
  427.  
  428. return $classes;
  429. }
  430. add_filter( 'body_class', 'twentytwelve_body_class' );
  431.  
  432. /**
  433. * Adjusts content_width value for full-width and single image attachment
  434. * templates, and when there are no active widgets in the sidebar.
  435. *
  436. * @since Twenty Twelve 1.0
  437. */
  438. function twentytwelve_content_width() {
  439. if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
  440. global $content_width;
  441. $content_width = 960;
  442. }
  443. }
  444. add_action( 'template_redirect', 'twentytwelve_content_width' );
  445.  
  446. /**
  447. * Add postMessage support for site title and description for the Theme Customizer.
  448. *
  449. * @since Twenty Twelve 1.0
  450. *
  451. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  452. * @return void
  453. */
  454. function twentytwelve_customize_register( $wp_customize ) {
  455. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  456. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  457. }
  458. add_action( 'customize_register', 'twentytwelve_customize_register' );
  459.  
  460. /**
  461. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  462. *
  463. * @since Twenty Twelve 1.0
  464. */
  465. /*function twentytwelve_customize_preview_js() {
  466. wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20120827', true );
  467. }
  468. add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
  469.  
  470. /*zzz add lightbox*/
  471.  
  472. /*add_action( 'wp_enqueue_scripts', 'frontend_scripts_include_lightbox' );
  473. function frontend_scripts_include_lightbox() {
  474.  
  475. global $woocommerce;
  476. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
  477. $lightbox_en = get_option( 'woocommerce_enable_lightbox' ) == 'yes' ? true : false;
  478.  
  479. if ( $lightbox_en ) {
  480.  
  481. wp_enqueue_script( 'prettyPhoto', $woocommerce->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), '1.6', true );
  482.  
  483. wp_enqueue_script( 'prettyPhotoInit', $woocommerce->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery' ), '2.0.8', true );
  484.  
  485. wp_enqueue_style( 'woocommerce_prettyPhoto_styles', $woocommerce->plugin_url() . '/assets/css/prettyPhoto.css' );
  486.  
  487. wp_enqueue_script( 'zzz-add-catalog-zoom' , get_bloginfo('template_directory').'/zzz-add-catalog-zoom.js' , array('jquery') );
  488. // Localize the script with new data
  489. $zoom_object = array(
  490. 'blog_url' => get_bloginfo('url'),
  491. 'temp_url' => get_bloginfo('template_url'),
  492. );
  493. wp_localize_script( 'zzz-add-catalog-zoom', 'zoom_object', $zoom_object );
  494.  
  495. }
  496.  
  497. }*/
  498.  
  499. /*zzz add 'show all products' view*/
  500.  
  501. /*if( isset( $_GET['printable'] ) ){
  502. add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 800;' ) );
  503. wp_enqueue_style( 'zzz_printable_styles', $woocommerce->plugin_url() . '/assets/css/zzz-printable.css' );
  504. }*/
  505.  
  506. add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );
  507. @ini_set( 'upload_max_size' , '64M' );
  508. @ini_set( 'post_max_size', '64M');
  509. @ini_set( 'max_execution_time', '300' );
  510.  
  511.  
  512.  
  513. // Display Fields
  514. add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
  515.  
  516. // Save Fields
  517. add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
  518.  
  519. function woo_add_custom_general_fields() {
  520.  
  521. global $woocommerce, $post;
  522.  
  523. echo '<div class="options_group">';
  524.  
  525. // Text Field
  526. woocommerce_wp_text_input(
  527. array(
  528. 'id' => '_condrep',
  529. 'label' => __( 'Condition Report', 'woocommerce' ),
  530. 'placeholder' => '',
  531. 'desc_tip' => 'good',
  532. 'description' => __( 'Enter the custom value here.', 'woocommerce' )
  533. )
  534. );
  535.  
  536.  
  537.  
  538.  
  539. // Custom fields will be created here...
  540.  
  541. echo '</div>';
  542.  
  543. }
  544.  
  545. function woo_add_custom_general_fields_save( $post_id ){
  546.  
  547. // Text Field
  548. $woocommerce_text_field = $_POST['_condrep'];
  549. if( !empty( $woocommerce_text_field ) )
  550. update_post_meta( $post_id, '_condrep', esc_attr( $woocommerce_text_field ) );
  551.  
  552. }
  553. /*
  554. add_action( 'woocommerce_product_write_panel_tabs', 'woo_add_custom_admin_product_tab' );
  555.  
  556. function woo_add_custom_admin_product_tab() {
  557. ?>
  558. <li class="custom_tab"><a href="#custom_tab_data"><?php _e('My Custom Tab', 'woocommerce'); ?></a></li>
  559. <?php
  560. }*/
  561.  
  562. function woocommerce_short_description($excerpt){
  563. global $post;
  564. if(get_post_meta($post->ID,'_condrep',true) !=''){
  565. $excerpt = $excerpt."<span class='condition_rep'>Condition: ".get_post_meta($post->ID,'_condrep',true).'</span>';
  566. }
  567. return $excerpt;
  568. }
  569. add_filter('woocommerce_short_description','woocommerce_short_description');
  570.  
  571.  
  572.  
  573.  
  574. //add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
  575.  
  576.  
  577. /*function custom_woocommerce_get_catalog_ordering_args( $args ) {
  578. $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
  579.  
  580. if ( 'alphabetical' == $orderby_value ) {
  581. $args['orderby'] = 'title';
  582. $args['order'] = 'asc';
  583. $args['meta_value'] = 'DECIMAL';
  584. }
  585.  
  586. return $args;
  587. }*/
  588.  
  589. // add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
  590. // add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
  591.  
  592. // function custom_woocommerce_catalog_orderby( $sortby ) {
  593. // $sortby['alphabetical'] = 'Aplhabetical';
  594. // return $sortby;
  595. // }
  596.  
  597.  
  598. // function orderby_post_title_int( $orderby )
  599.  
  600. // {
  601.  
  602. // if(!is_admin() && (is_archive() || is_category() || is_tax())){
  603. // return '(wp_posts.post_title+0) ASC';
  604.  
  605. // }else{
  606. // return $orderby;
  607. // }
  608. // }
  609. // add_filter('posts_orderby', 'orderby_post_title_int' );
  610. //remove_filter('posts_orderby', 'orderby_post_title_int' );
  611. class My_Walker_Nav_Menu extends Walker_Nav_Menu {
  612. function start_lvl(&$output, $depth) {
  613. $indent = str_repeat("\t", $depth);
  614. $output .= "\n$indent<ul class=\"dropdown-menu\">\n";
  615. }
  616. }
  617.  
  618. add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
  619. function special_nav_class($classes, $item){
  620. if( in_array('current-menu-item', $classes) ){
  621. $classes[] = 'active ';
  622. }
  623. return $classes;
  624. }
  625.  
  626. add_action( 'after_setup_theme', 'baw_theme_setup' );
  627. function baw_theme_setup() {
  628. add_image_size( 'home_thumb1', 499,499,true ); // 300 pixels wide (and unlimited height)
  629. add_image_size( 'home_thumb2', 749, 499, true ); // (cropped)
  630. }
  631.  
  632. add_filter( 'wp_mail_from_name', 'custom_wp_mail_from_name' );
  633. function custom_wp_mail_from_name( $original_email_from ) {
  634. return 'SRJewellery';
  635. }
  636.  
  637.  
  638. /*
  639. * goes in theme functions.php or a custom plugin. Replace the image filename/path with your own :)
  640. *
  641. **/
  642. add_action( 'init', 'custom_fix_thumbnail' );
  643.  
  644. // function woocommerce_shortcode_products_query_ar($args) {
  645. // if(is_product_category()) {
  646. // return $args['orderby'] = 'rating';
  647. // }
  648.  
  649. // }
  650. // add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_query_ar' );
  651.  
  652. // function exclude_category( $query ) {
  653. // if ( is_product_category() && $query->is_main_query() ) {
  654. // $query->set( 'orderby', 'title' );
  655. // $query->set( 'posts_per_page', -1 );
  656. // }
  657. // }
  658. // add_action( 'pre_get_posts', 'exclude_category', 10 );
  659.  
  660. function custom_fix_thumbnail() {
  661. add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
  662.  
  663. function custom_woocommerce_placeholder_img_src( $src ) {
  664.  
  665. $src= get_bloginfo('template_url').'/images/image-to-follow.jpg';
  666.  
  667. return $src;
  668. }
  669. }
  670. /********* hide ordering catalog ************/
  671. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
  672. /******* serch form shortcode ************/
  673. add_shortcode( 'search_product', 'product_search_form' );
  674. function product_search_form( ) {
  675. get_product_search_form();
  676. }
  677. /**
  678. * Remove readmore.
  679. */
  680.  
  681.  
  682.  
  683.  
  684. remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  685. add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
  686.  
  687.  
  688. if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
  689. function woocommerce_template_loop_product_thumbnail() {
  690. echo woocommerce_get_product_thumbnail();
  691. }
  692. }
  693. if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {
  694. function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) {
  695. global $post, $woocommerce;
  696. // $output = '<div class="imagewrapper">';
  697. $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), $size );
  698. $full_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
  699. if ( has_post_thumbnail() ) {
  700. $output .= '<img width="400" height="400" src="'.$image_src[0].'" data-full-image="'.$full_url.'" class="attachment-shop_catalog wp-post-image" alt="4c">';
  701. }
  702. // $output .= '</div>';
  703. return $output;
  704. }
  705. }
  706. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  707. add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
  708.  
  709. function woo_remove_product_tabs( $tabs ) {
  710.  
  711. unset( $tabs['description'] ); // Remove the description tab
  712. unset( $tabs['reviews'] ); // Remove the reviews tab
  713. unset( $tabs['additional_information'] ); // Remove the additional information tab
  714.  
  715. return $tabs;
  716.  
  717. }
  718. remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
  719. remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar',10);
  720. // remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
  721.  
  722. add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );
  723.  
  724. function add_custom_field() {
  725. global $post;
  726.  
  727. echo "<div class='summary'><p class='prod-code'>";
  728. $sub_title = get_post_meta( get_the_ID(), "sub_title", true);
  729. echo $sub_title;
  730. echo "</p></div>";
  731.  
  732. return true;
  733. }
  734. add_action( 'woocommerce_after_single_product_summary', 'add_custom_content', 0 );
  735.  
  736. function add_custom_content() {
  737. global $post;
  738.  
  739. echo "<div class='summary'><p class='prod-code'>";
  740.  
  741. echo the_content();
  742. echo "</p></div>";
  743.  
  744. return true;
  745. }
  746. add_action( 'woocommerce_after_single_product_summary', 'add_custom_enqure', 0 );
  747.  
  748. function add_custom_enqure() {
  749. global $post;
  750. global $product;
  751. echo '<div class="single-product-button summary">';
  752. echo '<p>'. $product->get_price_html() .'</p>';
  753. do_action( 'woocommerce_simple_add_to_cart' );
  754. echo '</div>';
  755. echo "<div class='summary'>";
  756.  
  757. echo ot('enquire');
  758. echo "</div>";
  759.  
  760. return true;
  761. }
  762. function woocommerce_result_count() {
  763. return;
  764. }
  765. add_action( 'woocommerce_category_showimage', 'woocommerce_category_image', 2 );
  766. function woocommerce_category_image() {
  767. if ( is_product_category() ){
  768. global $wp_query;
  769. $cat = $wp_query->get_queried_object();
  770. $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
  771. $image = wp_get_attachment_url( $thumbnail_id );
  772. if ( $image ) {
  773. echo '<img src="' . $image . '" alt="category image" />';
  774. }
  775. }
  776. }
  777. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
  778. remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  779.  
  780. add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
  781. add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
  782.  
  783. function my_theme_wrapper_start() {
  784. echo '<div class="product-div"><div class="contanier">';
  785. }
  786.  
  787. function my_theme_wrapper_end() {
  788. echo '</div></div>';
  789. }
  790. add_action( 'woocommerce_product_galerys', 'woocommerce_gallerys_image', 2 );
  791. function woocommerce_gallerys_image() {
  792. global $post, $product, $woocommerce;
  793.  
  794. $attachment_ids = $product->get_gallery_attachment_ids();
  795.  
  796. if ( $attachment_ids ) {
  797. ?>
  798. <ul><?php
  799.  
  800. $loop = 0;
  801. $columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
  802.  
  803. foreach ( $attachment_ids as $attachment_id ) {
  804.  
  805. $classes = array( 'zoom' );
  806.  
  807. if ( $loop == 0 || $loop % $columns == 0 )
  808. $classes[] = 'first';
  809.  
  810. if ( ( $loop + 1 ) % $columns == 0 )
  811. $classes[] = 'last';
  812.  
  813. $image_link = wp_get_attachment_url( $attachment_id );
  814.  
  815. if ( ! $image_link )
  816. continue;
  817.  
  818. $image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
  819. $image_class = esc_attr( implode( ' ', $classes ) );
  820. $image_title = esc_attr( get_the_title( $attachment_id ) );
  821.  
  822. echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<li><img src="%s"/></li>', $image_link, $image_class, $image_title, $image ), $attachment_id, $post->ID, $image_class );
  823.  
  824. $loop++;
  825. }
  826.  
  827. ?></ul>
  828. <?php
  829. }
  830. }
  831. add_action( 'woocommerce_first_image', 'woocommerce_first_imageone', 2 );
  832. function woocommerce_first_imageone() {
  833. global $post, $product, $woocommerce;
  834.  
  835. $attachment_ids = $product->get_gallery_attachment_ids();
  836. $first_image = null;
  837. if ( $attachment_ids ) {
  838. ?>
  839. <?php
  840.  
  841.  
  842. $first_image = wp_get_attachment_url( $attachment_ids[0] );
  843.  
  844. if ( ! $first_image )
  845. continue;
  846.  
  847. $image = wp_get_attachment_image( $attachment_ids[0], apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
  848.  
  849. $image_title = esc_attr( get_the_title( $attachment_ids[0] ) );
  850.  
  851. echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<img class="carouselimage" src="%s"/>', $first_image, $image_title, $image ), $attachment_ids[0], $post->ID );
  852.  
  853.  
  854.  
  855.  
  856. ?>
  857. <?php
  858. }
  859. }
  860.  
  861.  
  862.  
  863.  
  864.  
  865. /**
  866. * Welcome PopUp Form
  867. *
  868. */
  869. function pixiefy_add_modal_to_footer() {
  870. global $pybus_option; ?>
  871. <div id="welcomeModal" class="welcome-popup mfp-hide white-popup">
  872. <div class="po-footer-form">
  873. <div class="popup-container">
  874. <button type="button" class="popup-close" onClick="closePopup();">x</button>
  875. <div class="po-footer-form-container">
  876. <?php echo do_shortcode( '[contact-form-7 id="953" title="PopUp Form"]' ); ?>
  877. </div>
  878. </div>
  879. </div> <!-- // END FOOTER FORM -->
  880. </div> <?php
  881. }
  882.  
  883. function first_time_visit() {
  884. if (empty($_COOKIE['first_time'])) {
  885. add_action('wp_footer', 'pixiefy_add_modal_to_footer');
  886. }
  887. setcookie("first_time", 1, time()+(60*60*24*365*5)); /* expire in 5 Year */
  888. }
  889. first_time_visit();
  890.  
  891.  
  892.  
  893. function get_image_by_id($image_url) {
  894. global $wpdb;
  895. $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
  896. return $attachment[0];
  897. }
  898.  
  899. add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
  900.  
  901. function woocommerce_catalog_orderby_ar($order_by_ar){
  902. unset($order_by_ar['rating']);
  903. return $order_by_ar;
  904. }
  905. add_filter( 'woocommerce_catalog_orderby', 'woocommerce_catalog_orderby_ar' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement