Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 44.37 KB | None | 0 0
  1. <?php
  2.  
  3. require_once __DIR__ .'/vendor/autoload.php';
  4.  
  5. add_action('wp_ajax_nopriv_logout-link', 'logoutLink');
  6. add_action('wp_ajax_logout-link', 'logoutLink');
  7.  
  8. function logoutLink()
  9. {
  10.     echo wp_logout_url(get_bloginfo('url'));
  11.     die(1);
  12. }
  13.  
  14. //wp_all_import Disable checking for duplicates
  15. //add_filter('wp_all_import_is_check_duplicates', 'disable_check_dupe_func', 10, 2);
  16.  
  17. //Disable checking for duplicates
  18. function disable_check_dupe_func($truefalse, $thisid){
  19.     return false;
  20. }
  21.  
  22.  
  23. function domain_title()
  24. {
  25.     return DOMAIN_TITLE;
  26. }
  27.  
  28. add_shortcode('domain_title', 'domain_title');
  29. function shortcode_handler()
  30. {
  31.     return TELEPHONE;
  32. }
  33.  
  34. add_shortcode('telephone_short', 'shortcode_handler');
  35. function addres_handler()
  36. {
  37.     return ADDRESS;
  38. }
  39.  
  40. add_shortcode('addres_handler', 'addres_handler');
  41.  
  42.  
  43. add_shortcode('wishlist_custom', 'wish_show');
  44.  
  45. function wish_show()
  46. {
  47.     $query_args = [];
  48.     if (empty($wishlist_id)) {
  49.         if (!empty($action) && $action == 'user') {
  50.             $user_id = isset($action_params[ 1 ]) ? $action_params[ 1 ] : false;
  51.             $user_id = (!$user_id) ? get_query_var($user_id, false) : $user_id;
  52.             $user_id = (!$user_id) ? get_current_user_id() : $user_id;
  53.  
  54.             $wishlists = YITH_WCWL()->get_wishlists(['user_id' => $user_id, 'is_default' => 1]);
  55.  
  56.             if (!empty($wishlists) && isset($wishlists[ 0 ])) {
  57.                 $wishlist_id = $wishlists[ 0 ][ 'wishlist_token' ];
  58.             } else {
  59.                 $wishlist_id = false;
  60.             }
  61.         } else {
  62.             $wishlist_id = isset($action_params[ 1 ]) ? $action_params[ 1 ] : false;
  63.             $wishlist_id = (!$wishlist_id) ? get_query_var('wishlist_id', false) : $wishlist_id;
  64.         }
  65.     }
  66.  
  67.     $is_user_owner = false;
  68.     $query_args = [];
  69.  
  70.     if (!empty($user_id)) {
  71.         $query_args[ 'user_id' ] = $user_id;
  72.         $query_args[ 'is_default' ] = 1;
  73.  
  74.         if (get_current_user_id() == $user_id) {
  75.             $is_user_owner = true;
  76.         }
  77.     } elseif (!is_user_logged_in()) {
  78.         if (empty($wishlist_id)) {
  79.             $query_args[ 'wishlist_id' ] = false;
  80.             $is_user_owner = true;
  81.         } else {
  82.             $is_user_owner = false;
  83.  
  84.             $query_args[ 'wishlist_token' ] = $wishlist_id;
  85.             $query_args[ 'wishlist_visibility' ] = 'visible';
  86.         }
  87.     } else {
  88.         if (empty($wishlist_id)) {
  89.             $query_args[ 'user_id' ] = get_current_user_id();
  90.             $query_args[ 'is_default' ] = 1;
  91.             $is_user_owner = true;
  92.         } else {
  93.             $wishlist = YITH_WCWL()->get_wishlist_detail_by_token($wishlist_id);
  94.             $is_user_owner = $wishlist[ 'user_id' ] == get_current_user_id();
  95.  
  96.             $query_args[ 'wishlist_token' ] = $wishlist_id;
  97.  
  98.             if (!empty($wishlist) && $wishlist[ 'user_id' ] != get_current_user_id()) {
  99.                 $query_args[ 'user_id' ] = false;
  100.                 if (!current_user_can('manage_options')) {
  101.                     $query_args[ 'wishlist_visibility' ] = 'visible';
  102.                 }
  103.             }
  104.         }
  105.     }
  106.     $whishlis_items = YITH_WCWL()->get_products($query_args);
  107.     ob_start();
  108.     ?>
  109.     <ul style="width: 302px;">
  110.         <?php foreach ($whishlis_items as $item):
  111.             $_product = wc_get_product($item[ 'prod_id' ]);
  112.             $link = get_permalink($item[ 'prod_id' ]);
  113.             ?>
  114.             <li>
  115.                 <div style="clear:both;"></div>
  116.                 <a class="product" href="<?php echo $link; ?>">
  117.                     <img width="90"
  118.                          src="<?php echo get_the_post_thumbnail_url($item[ 'prod_id' ], [80, 80]); ?>">
  119.                     <?php echo $_product->get_title(); ?>
  120.                 </a>
  121.             </li>
  122.         <?php endforeach; ?>
  123.  
  124.     </ul>
  125.     <?php
  126.     $response = ob_get_contents();
  127.     ob_end_clean();
  128.  
  129.     return $response;
  130. }
  131.  
  132. include_once 'functions/CBC.php';
  133. include_once 'widgets/filters.php';
  134. include_once 'functions/ThanksPage.php';
  135. require_once(ABSPATH . 'wp-admin/includes/image.php');
  136. add_action('wp_enqueue_scripts', 'theme_name_scripts');
  137.  
  138. add_action('rest_api_init', function ($server) {
  139.     $server->register_route('login', '/login321', [
  140.         'methods'  => 'POST',
  141.         'callback' => 'login_modal',
  142.     ]);
  143. });
  144. add_action('rest_api_init', function ($server) {
  145.     $server->register_route('register', '/register', [
  146.         'methods'  => 'POST',
  147.         'callback' => 'Register_modal',
  148.     ]);
  149. });
  150. add_action('rest_api_init', function ($server) {
  151.     $server->register_route('sendPass', '/sendPass', [
  152.         'methods'  => 'POST',
  153.         'callback' => 'SendPassModal',
  154.     ]);
  155. });
  156.  
  157. /**
  158.  * @return string
  159.  */
  160. function login_modal()
  161. {
  162.     $creds = [
  163.         'user_login'    => $_POST('username'),
  164.         'user_password' => $_POST('password'),
  165.         'remember'      => true,
  166.     ];
  167.  
  168.     $user = wp_signon($creds, false);
  169.  
  170.     if (is_wp_error($user)) {
  171.         return json_encode(['success' => true]);
  172.     } else {
  173.         return json_encode(['success' => false, 'message' => $user->get_error_message(), 'error' => $user->get_error_code()]);
  174.     }
  175. }
  176.  
  177. function SendPassModal()
  178. {
  179.     if (email_exists($_POST[ 'socialogin_email_forgot' ]) && ($_POST[ 'socialogin_email_forgot' ] != '')) {
  180.         $password = wp_generate_password();
  181.  
  182.         $user = get_user_by('email', sanitize_text_field($_POST[ 'socialogin_email_forgot' ]));
  183.         wp_set_password($password, $user->id);
  184.         wpse_user_password_notification($user->id, $password);
  185.  
  186.         return json_encode(['success' => true, 'message' => 'A new password has been sent to your e-mail']);
  187.     }
  188.  
  189.     return json_encode(['success' => false, 'message' => 'Can\'t find user with this email', 'error' => 'no user with this email']);
  190. }
  191.  
  192. function Register_modal()
  193. {
  194.     if (($_POST[ 'email' ] != '') && ($_POST[ 'pass' ] == $_POST[ 'passConfirm' ])) {
  195.         //$user = wp_create_user(sanitize_text_field($_POST[ 'username' ]), sanitize_text_field($_POST[ 'pass' ]), sanitize_text_field($_POST[ 'email' ]));
  196.  
  197.         $default_newuser = [
  198.             'user_pass'  => sanitize_text_field($_POST[ 'pass' ]),
  199.             'user_login' => sanitize_text_field($_POST[ 'username' ]),
  200.             'user_email' => sanitize_text_field($_POST[ 'email' ]),
  201.             'role'       => 'subscriber',
  202.         ];
  203.         $user_id = wp_insert_user($default_newuser);
  204.         if ($user_id && !is_wp_error($user_id)) {
  205.             $code = sha1($user_id . time());
  206.             $activation_link = add_query_arg(['key' => $code, 'user' => $user_id], get_permalink(266319));
  207.             //add_user_meta($user_id, 'has_to_be_activated', $code, true);
  208.             //$headers[] = 'From: ICONIC '.HOME_TITLE;
  209.             $headers = ['Content-Type: text/html; charset=UTF-8', 'From: ICONIC ' . HOME_TITLE . ' <info@iconicjewelry.com>'];
  210.             ob_start();
  211.             include(locate_template('mail-register.php'));
  212.             $response = ob_get_contents();
  213.             ob_end_clean();
  214.             if (!wp_mail(sanitize_text_field($_POST[ 'email' ]), 'ACTIVATION LINK', $response, $headers)) {
  215.                 return json_encode(['success' => false, 'message' => 'Error', 'error' => '123']);
  216.             }
  217.  
  218.             return json_encode(['success' => true, 'message' => 'Activation link has been sent to your e-mail']);
  219.         } else {
  220.  
  221.             return json_encode(['success' => false, 'message' => $user_id->get_error_message(), 'error' => $user_id->get_error_code()]);
  222.         }
  223.     }
  224.  
  225.     return json_encode(['success' => false]);
  226. }
  227.  
  228. function wpml_custom_flags()
  229. {
  230.  
  231.     $languages = icl_get_languages('skip_missing=1');
  232.     $curr_lang = [];
  233.     if (!empty($languages)) {
  234.  
  235.         foreach ($languages as $language) {
  236.             if (!empty($language[ 'active' ])) {
  237.                 $curr_lang = $language; // This will contain current language info.
  238.                 break;
  239.             }
  240.         }
  241.     }
  242.  
  243.     return $curr_lang;
  244. }
  245.  
  246. function wpse_user_password_notification($user_id, $plaintext_pass = '')
  247. {
  248.     if (empty($plaintext_pass))
  249.         return false;
  250.  
  251.     $user = get_userdata($user_id);
  252.     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  253.     $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
  254.     $message .= sprintf(__('New Password: %s'), $plaintext_pass) . "\r\n";
  255.     $message .= get_bloginfo('url') . "\r\n";
  256.  
  257.     return wp_mail($user->user_email, sprintf(__('[%s] Your username and new password'), $blogname), $message);
  258. }
  259.  
  260.  
  261. add_action('template_redirect', 'wpse8170_activate_user');
  262. function wpse8170_activate_user()
  263. {
  264.     if (is_page() && get_the_ID() == 266319) {
  265.         $user_id = filter_input(INPUT_GET, 'user', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
  266.         if ($user_id) {
  267.             // get user meta activation hash field
  268.             //$code = get_user_meta($user_id, 'has_to_be_activated', true);
  269.             //if ($code == filter_input(INPUT_GET, 'key')) {
  270.             //  delete_user_meta($user_id, 'has_to_be_activated');
  271.             //}
  272.         }
  273.     }
  274. }
  275.  
  276. add_filter('authenticate', 'my_custom_authenticate', 10, 3);
  277. function my_custom_authenticate($user, $username, $password)
  278. {
  279.     $user = get_user_by('login', $username);
  280.     if ($user == null) {
  281.         $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));
  282.     } elseif (0) { //get_user_meta($user->ID, 'has_to_be_activated', true)) {
  283.         remove_action('authenticate', 'wp_authenticate_username_password', 20);
  284.         remove_action('authenticate', 'wp_authenticate_email_password', 20);
  285.         $user = new WP_Error('denied', __('<strong>ERROR</strong>: User is not activated.'));
  286.     }
  287.  
  288.     return null;
  289. }
  290.  
  291. add_filter('body_class', 'custom_class');
  292. function custom_class($classes)
  293. {
  294.     if (is_front_page()):
  295.         $classes[] = "cms-home";
  296.         $classes[] = "cms-index-index ";
  297.     endif;
  298.     if (is_product()):
  299.         $classes[] = "catalog-product-view";
  300.     endif;
  301.     if (is_product_category()):
  302.         $classes[] = "catalog-category-view";
  303.     endif;
  304.     if (is_product_category()) {
  305.         unset($classes[ array_search('woocommerce', $classes) ]);
  306.         unset($classes[ array_search('woocommerce-page', $classes) ]);
  307.  
  308.     }
  309.  
  310.     return $classes;
  311. }
  312.  
  313. // add_action('wp_print_styles', 'theme_name_scripts'); // можно использовать этот хук он более поздний
  314. function theme_name_scripts()
  315. {
  316.     global $WOOCS;
  317.     wp_enqueue_style('iconic-script', get_template_directory_uri() . '/assets/css/main-2.css');
  318.     wp_enqueue_style('iconic-script-media', get_template_directory_uri() . '/assets/css/media.css');
  319.     wp_enqueue_style('grid', get_template_directory_uri() . '/assets/css/grid.css');
  320.     wp_enqueue_style('MyFontsWebfontsKit', get_template_directory_uri() . '/assets/css/main.css');
  321.  
  322.     wp_enqueue_style('FA-fonts', get_template_directory_uri() . '/assets/css/font-awesome.min.css');
  323.     wp_enqueue_script('noconflict-js', get_template_directory_uri() . '/assets/js/noConflict.js', ['jquery'], '', false);
  324.     wp_enqueue_script('selectbox-js', get_template_directory_uri() . '/assets/js/jquery.selectbox-0.2.min.js', [], '', false);
  325.     wp_enqueue_script('fancybox-js', get_template_directory_uri() . '/assets/js/jquery.fancybox-1.3.4.pack.js', [], '', false);
  326.     wp_enqueue_script('main-js', get_template_directory_uri() . '/assets/js/main-app.js', [], '1.15', false);
  327.     wp_localize_script('main-js', 'price_f',
  328.         [
  329.  
  330.             'currency__symbol' => get_woocommerce_currency_symbol(),
  331.             'cur_curr'         => $WOOCS->current_currency,
  332.         ]
  333.     );
  334.  
  335.     wp_enqueue_script('slick-js', get_template_directory_uri() . '/assets/js/slick.js', ['jquery'], '1.20', true);
  336.     wp_enqueue_script('popup', get_template_directory_uri() . '/assets/js/mb_popup.js', [], '1.20', true);
  337.     wp_enqueue_script('product-js', get_template_directory_uri() . '/assets/js/product.js', [], '1.20', true);
  338.     wp_localize_script('product-js', 'myajax',
  339.         [
  340.             'url'   => admin_url('admin-ajax.php'),
  341.             'nonce' => wp_create_nonce('myajax-nonce'),
  342.  
  343.         ]
  344.     );
  345.  
  346.     wp_enqueue_script('lazy-js', get_template_directory_uri() . '/assets/js/jquery.lazyload.min.js', ['jquery'], '1.20', true);
  347.  
  348.     if (is_page('faq')) {
  349.         wp_enqueue_script('faq-js', get_template_directory_uri() . '/assets/js/faq.js', [], '1.20', true);
  350.     }
  351.     if (is_page('press')) {
  352.         wp_enqueue_script('press-js', get_template_directory_uri() . '/assets/js/press.js', [], '1.20', true);
  353.     }
  354.     if (is_product_category()):
  355.         wp_enqueue_script('jquery.endless-scroll', get_template_directory_uri() . '/assets/js/jquery.endless-scroll.js', ['jquery'], '1.20', true);
  356.       wp_enqueue_script('category-js', get_template_directory_uri() . '/assets/js/category.js', [], '1.20', true);
  357.  
  358.         wp_localize_script('category-js', 'myajax',
  359.             [
  360.                 'url'   => admin_url('admin-ajax.php'),
  361.                 'nonce' => wp_create_nonce('myajax-nonce'),
  362.             ]
  363.         );
  364.     endif;
  365.     if (is_page('checkout')) {
  366.         wp_enqueue_style('checkout', get_template_directory_uri() . '/assets/css/checkout.css');
  367.     }
  368.  
  369. }
  370.  
  371.  
  372. //
  373. // add_filter('request', function( $vars ) {
  374. //  global $wpdb;
  375. //  if( ! empty( $vars['pagename'] ) || ! empty( $vars['category_name'] ) || ! empty( $vars['name'] ) || ! empty( $vars['attachment'] ) ) {
  376. //      $slug = ! empty( $vars['pagename'] ) ? $vars['pagename'] : ( ! empty( $vars['name'] ) ? $vars['name'] : ( !empty( $vars['category_name'] ) ? $vars['category_name'] : $vars['attachment'] ) );
  377. //      $exists = $wpdb->get_var( $wpdb->prepare( "SELECT t.term_id FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'product_cat' AND t.slug = %s" ,array( $slug )));
  378. //      if( $exists ){
  379. //          $old_vars = $vars;
  380. //          $vars = array('product_cat' => $slug );
  381. //          if ( !empty( $old_vars['paged'] ) || !empty( $old_vars['page'] ) )
  382. //              $vars['paged'] = ! empty( $old_vars['paged'] ) ? $old_vars['paged'] : $old_vars['page'];
  383. //          if ( !empty( $old_vars['orderby'] ) )
  384. //                  $vars['orderby'] = $old_vars['orderby'];
  385. //                  if ( !empty( $old_vars['order'] ) )
  386. //                      $vars['order'] = $old_vars['order'];
  387. //      }
  388. //  }
  389. //  return $vars;
  390. // });
  391.  
  392. add_filter('body_class', function (array $classes) {
  393.     if (in_array('blog', $classes)) {
  394.         unset($classes[ array_search('blog', $classes) ]);
  395.     }
  396.  
  397.     return $classes;
  398. });
  399.  
  400. function get_level2($category, $level = 0)
  401. {
  402.     $children = get_terms('product_cat', [
  403.         'parent'     => $category->term_id,
  404.         'hide_empty' => false,
  405.     ]);
  406.     if (!$children) {
  407.         return $level;
  408.     } else {
  409.         $level++;
  410.         $category = get_terms('product_cat', [
  411.             'parent'     => $category->term_id,
  412.             'hide_empty' => false,
  413.         ]);
  414.  
  415.         return get_level2($category[ 1 ], $level);
  416.     }
  417. }
  418.  
  419. add_action('after_setup_theme', 'woocommerce_support');
  420. function woocommerce_support()
  421. {
  422.     load_theme_textdomain('IconicJew', get_template_directory() . '/languages');
  423.     add_theme_support('woocommerce');
  424.  
  425.     add_theme_support('wc-product-gallery-zoom');
  426.     add_theme_support('wc-product-gallery-lightbox');
  427.     add_theme_support('wc-product-gallery-slider');
  428. }
  429.  
  430. /**
  431.  * Register our sidebars and widgetized areas.
  432.  *
  433.  */
  434. function arphabet_widgets_init()
  435. {
  436.  
  437.     register_sidebar([
  438.         'name'          => 'Category filters',
  439.         'id'            => 'cat_1',
  440.         'before_widget' => '<div class="amshopby-item-top block-content am-toggle-content"><dl id="narrow-by-list" class="amshopby-narrow-by-list widget %2$s">',
  441.         'after_widget'  => '</dl></div>',
  442.         'before_title'  => '<dt>',
  443.         'after_title'   => '</dt>',
  444.     ]);
  445.     register_sidebar([
  446.         'name'          => 'Category filters right',
  447.         'id'            => 'cat_2',
  448.         'before_widget' => '<div class="amshopby-item-top block-content am-toggle-content"><dl id="narrow-by-list" class="amshopby-narrow-by-list widget %2$s">',
  449.         'after_widget'  => '</dl></div>',
  450.         'before_title'  => '<dt>',
  451.         'after_title'   => '</dt>',
  452.     ]);
  453.     register_sidebar([
  454.         'name'          => 'header',
  455.         'id'            => 'cart_w',
  456.         'before_widget' => '<div class="header-cart">',
  457.         'after_widget'  => '</div>',
  458.         'before_title'  => '',
  459.         'after_title'   => '',
  460.     ]);
  461.     register_sidebar([
  462.         'name'          => 'Footer 1',
  463.         'id'            => 'block_1',
  464.         'before_widget' => '<div id="block_1" class="footer-area">',
  465.         'after_widget'  => '</div>',
  466.         'before_title'  => '<h6>',
  467.         'after_title'   => '</h6>',
  468.     ]);
  469.     register_sidebar([
  470.         'name'          => 'Footer 2',
  471.         'id'            => 'block_2',
  472.         'before_widget' => '<div id="block_2" class="footer-area">',
  473.         'after_widget'  => '</div>',
  474.         'before_title'  => '<h6>',
  475.         'after_title'   => '</h6>',
  476.     ]);
  477.     register_sidebar([
  478.         'name'          => 'Footer 3',
  479.         'id'            => 'block_3',
  480.         'before_widget' => '<div id="block_3" class="footer-area">',
  481.         'after_widget'  => '</div>',
  482.         'before_title'  => '<h6>',
  483.         'after_title'   => '</h6>',
  484.     ]);
  485.     register_sidebar([
  486.         'name'          => 'Footer 4',
  487.         'id'            => 'block_4',
  488.         'before_widget' => '<div id="block_4" class="footer-area">',
  489.         'after_widget'  => '</div>',
  490.         'before_title'  => '<h6>',
  491.         'after_title'   => '</h6>',
  492.     ]);
  493. }
  494.  
  495. add_action('widgets_init', 'arphabet_widgets_init');
  496.  
  497.  
  498. function woo_custom_ajax_variation_threshold($qty, $product)
  499. {
  500.     return 200;
  501. }
  502.  
  503. add_filter('woocommerce_ajax_variation_threshold', 'woo_custom_ajax_variation_threshold', 10, 2);
  504. add_filter('woocommerce_sale_flash', 'woo_custom_hide_sales_flash');
  505. function woo_custom_hide_sales_flash()
  506. {
  507.     return false;
  508. }
  509.  
  510.  
  511. function get_product_by_sku($sku)
  512. {
  513.  
  514.     global $wpdb;
  515.  
  516.     $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku));
  517.  
  518.     if ($product_id)
  519.         return new WC_Product($product_id);
  520.  
  521.     return null;
  522. }
  523.  
  524. //add_action('pmxi_saved_post', 'post_saved', 10, 1);
  525.  
  526. function post_saved($id)
  527. {
  528.  
  529.  
  530.   // ------------- WPML translator -------------------------
  531.  
  532.  
  533.  
  534.     //$id_d = apply_filters('wpml_object_id', $id, 'product', TRUE,'en');
  535.     //$thubm_id =get_post_meta($id_d,'_thumbnail_id', true);
  536.     //if($thubm_id==''){
  537.     //  $post = ['ID' => $id, 'post_status' => 'draft'];
  538.     //  wp_update_post($post);
  539.     //}
  540.     //else
  541.     //{
  542.     //  add_post_meta( $id, '_thumbnail_id', $thubm_id);
  543.     //}
  544.  
  545.  
  546.  
  547.     // ------------- end WPML translator -------------------------
  548.  
  549.  
  550.  
  551.     // ------------- import Comments -------------------------
  552.     /*
  553.     $comment_authors = get_post_meta($id, '_comment_auth', 'true');
  554.     $comment_text = get_post_meta($id, '_comment_text', 'true');
  555.     $comment_summary = get_post_meta($id, '_comment_summary', 'true');
  556.     $comment_rating = get_post_meta($id, '_comment_rating', 'true');
  557.  
  558.  
  559.         $commentdata = [
  560.             'comment_post_ID' => $id,
  561.             'comment_author'  => $comment_authors,
  562.             'comment_content' => $comment_text,
  563.             'comment_type'    => '',
  564.             'comment_parent'  => 0,
  565.             'user_ID'         => 0,
  566.         ];
  567.         $comment_id = wp_new_comment($commentdata);
  568.         update_comment_meta($comment_id, 'rating', $comment_rating);
  569.         update_comment_meta($comment_id, '_summary_review', $comment_summary);
  570.         update_comment_meta($comment_id, 'verified', 0);
  571.  
  572.         wp_update_comment_count($id, true);
  573.         */
  574.  
  575.  
  576.     // ------------- end import Comments -------------------------
  577.  
  578.  
  579.   // ------------- main import Products ----------------
  580.  
  581.     //$p1 = get_post_meta($id, '_video_name', true);
  582.     //
  583.     //$cat = get_post_meta($id, '_categories_ids', true);
  584.     //$cat = explode(',', $cat);
  585.     //$cat = array_map('intval', $cat);
  586.     //$cat = array_unique($cat);
  587.     //
  588.     //if ($p1 != '') {
  589.     //
  590.     //
  591.     //  $wp_upload_dir = wp_upload_dir();
  592.     //  $filename = $wp_upload_dir[ 'basedir' ] . '/wpallimport/files/video/' . $p1;
  593.     //
  594.     //  // The ID of the post this attachment is for.
  595.     //  $parent_post_id = $id;
  596.     //
  597.     //  // Check the type of file. We'll use this as the 'post_mime_type'.
  598.     //  $filetype = wp_check_filetype(basename($filename), null);
  599.     //
  600.     //  // Get the path to the upload directory.
  601.     //
  602.     //  // Prepare an array of post data for the attachment.
  603.     //  $attachment = [
  604.     //      'guid'           => $wp_upload_dir[ 'url' ] . '/' . basename($filename),
  605.     //      'post_mime_type' => $filetype[ 'type' ],
  606.     //      'post_title'     => preg_replace('/\.[^.]+$/', '', basename($filename)),
  607.     //      'post_content'   => '',
  608.     //      'post_status'    => 'inherit',
  609.     //  ];
  610.     //
  611.     //  // Insert the attachment.
  612.     //  $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
  613.     //
  614.     //  // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
  615.     //
  616.     //
  617.     //  // Generate the metadata for the attachment, and update the database record.
  618.     //  $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
  619.     //  $video_id = time();
  620.     //  $video = [[
  621.     //      'thumbn'   => (string)get_post_thumbnail_id($parent_post_id),
  622.     //      'id'       => 'ywcfav_video_id-' . $video_id,
  623.     //      'type'     => 'upload',
  624.     //      'featured' => 'featured',
  625.     //      'name'     => preg_replace('/\.[^.]+$/', '', basename($filename)),
  626.     //      'host'     => 'host',
  627.     //      'content'  => (string)$attach_id,
  628.     //  ]];
  629.     //  $video_featured = [
  630.     //      'id'   => 'ywcfav_video_id-' . $video_id,
  631.     //      'type' => 'video',
  632.     //  ];
  633.     //  add_post_meta($id, '_ywcfav_video', $video);
  634.     //  add_post_meta($id, '_ywcfav_featured_content', $video_featured);
  635.     //}
  636.     //wp_set_object_terms($id, $cat, 'product_cat');
  637.     //
  638.     //if (get_post_meta($id, '_check_parent', true) == 'configurable') {
  639.     //  $post = ['ID' => $id, 'post_status' => 'draft'];
  640.     //  wp_update_post($post);
  641.     //}
  642.  
  643.     // ------------- end main import Products ----------------
  644. }
  645.  
  646.  
  647. remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
  648.  
  649. remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
  650.  
  651.  
  652. add_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 10);
  653.  
  654. add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 20);
  655. function filter_descr($post_post_excerpt)
  656. {
  657.     return $post_post_excerpt;
  658. }
  659.  
  660. add_action('woocommerce_short_description', 'filter_descr', 10, 1);
  661.  
  662.  
  663. function generateRandomString($length = 11)
  664. {
  665.     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  666.     $charactersLength = strlen($characters);
  667.     $randomString = '';
  668.     for ($i = 0; $i < $length; $i++) {
  669.         $randomString .= $characters[ rand(0, $charactersLength - 1) ];
  670.     }
  671.  
  672.     return $randomString;
  673. }
  674.  
  675. add_filter('woocommerce_format_sale_price', 'custom_price_html', 100, 2);
  676. function custom_price_html($price, $product)
  677. {
  678.     $price = preg_replace('/<del>/', '', $price);
  679.     $price = preg_replace('/\<\/del>/', '', $price);
  680.     $price = preg_replace('/<ins>/', '', $price);
  681.     $price = preg_replace('/<\/ins>/', '', $price);
  682.     $i = 1;
  683.     $price = preg_replace('/woocommerce-Price-amount/', 'price old-price', $price, $i);
  684.     $price = preg_replace('/woocommerce-Price-amount/', 'price special-price', $price, $i);
  685.  
  686.     return $price;
  687. }
  688.  
  689.  
  690. add_filter('woocommerce_product_tabs', 'woo_rename_tabs', 98);
  691. function woo_rename_tabs($tabs)
  692. {
  693.     $tabs[ 'reviews' ][ 'title' ] = __('Product review');                // Rename the reviews tab
  694.     $tabs[ 'additional_information' ][ 'title' ] = __('Product Details');    // Rename the additional information tab
  695.  
  696.     return $tabs;
  697.  
  698. }
  699.  
  700. add_filter('woocommerce_product_tabs', 'woo_new_product_tab');
  701. function woo_new_product_tab($tabs)
  702. {
  703.  
  704.     // Adds the new tab
  705.  
  706.     $tabs[ 'test_tab' ] = [
  707.         'title'    => __('Your order includes', 'woocommerce'),
  708.         'priority' => 50,
  709.         'callback' => 'woo_new_product_tab_content',
  710.     ];
  711.  
  712.     return $tabs;
  713.  
  714. }
  715.  
  716. function woo_new_product_tab_content()
  717. {
  718.  
  719.     // The new tab content
  720.     echo '<h6>' . translate('Your Order Includes', 'IconicJew') . '</h6><ol><div class="oversized-h">' . translate('Your Order Includes', 'IconicJew') . '</div>';
  721.     echo '<div style="padding:10px 0 25px 0; margin-bottom:20px;" class="your-order-include"><div style="background:#f9f9f9; overflow:auto;">';
  722.     echo '<div style="width:29%; padding:2%; float:left;"><img src="' . get_template_directory_uri() . '/images/ordering.png" width="100%" height="auto"></div><div style="width:29%; padding:2%;float:left;"><h2 style="border:none;">' . translate('SHIPPING DETAILS', 'IconicJew') . '</h2>';
  723.     echo '<p>' . translate('FREE insured shipping for all orders', 'IconicJew') . '</p><p></p><p>' . translate('Delivery time is around 16 days. 10 days for manufacturing and 6 days for expedite shipping.', 'IconicJew') . '</p></div>';
  724.     echo '<div style="width:30%; padding:2%; float:left;">';
  725.     echo '<div style="border:3px solid #304071; display:inline-block; margin:0 auto; padding:10px 30px 0 30px;" class="yoi">';
  726.     echo '<p style="font-size:15px;" align="center">' . translate('YOUR ORDER INCLUDES', 'IconicJew');
  727.     echo '</p><p align="left">';
  728.     echo '•' . translate(' Free FedEx Shipping World Wide', 'IconicJew') . '<br>';
  729.     echo '•' . translate(' Free 60 Day Returns', 'IconicJew') . ' <br>';
  730.     echo '•' . translate(' Professional Appraisal', 'IconicJew') . '<br>';
  731.     echo '•' . translate(' Complimentary Packaging', 'IconicJew') . '<br>';
  732.     echo '</p></div></div></div></div></ol>';
  733. }
  734.  
  735.  
  736. function save_comment_meta_data($comment_id)
  737. {
  738.     add_comment_meta($comment_id, '_summary_review', $_POST[ 'summary_review' ]);
  739. }
  740.  
  741. add_action('comment_post', 'save_comment_meta_data');
  742.  
  743.  
  744. function ico_register_widgets()
  745. {
  746.     register_widget('WC_Widget_Layered_Nav_Extended');
  747.     register_widget('WC_Widget_Layered_Nav_Extended_2');
  748.     register_widget('WC_Widget_Price_Filter_Ext');
  749.     // register_widget('WooCommerce_Widget_DropdownCart');
  750.  
  751. }
  752.  
  753. add_action('widgets_init', 'ico_register_widgets');
  754. add_filter('loop_shop_per_page', 'get_per_page', 20);
  755. function get_per_page()
  756. {
  757.     if (isset($_GET[ 'per_page' ]) && in_array($_GET[ 'per_page' ], [16, 32, 64])) {
  758.         return $_GET[ 'per_page' ];
  759.     } else {
  760.         if (wp_is_mobile()) {
  761.             return 16;
  762.         }
  763.  
  764.         return 32;
  765.     }
  766. }
  767.  
  768. add_action('init', 'create_posttype');
  769. function create_posttype()
  770. {
  771.     register_post_type('education_post',
  772.         [
  773.             'labels'       => [
  774.                 'name'          => __('Education'),
  775.                 'singular_name' => __('Education'),
  776.             ],
  777.             'public'       => true,
  778.             'hierarchical' => true,
  779.             'has_archive'  => true,
  780.             'rewrite'      => ['slug' => 'education'],
  781.             'supports'     => ['page-attributes', 'title', 'editor'],
  782.         ]
  783.     );
  784. }
  785.  
  786. add_action('wp_ajax_nopriv_get-diff-prod', 'get_prod');
  787. add_action('wp_ajax_get-diff-prod', 'get_prod');
  788. function get_prod()
  789. {
  790.  
  791.     $sku = $_POST[ 'data' ][ 'sku' ];
  792.     $metal = $_POST[ 'data' ][ 'Metal' ];
  793.     if ($_POST[ 'data' ][ 'Gemstone' ]) {
  794.         $Gemstone = $_POST[ 'data' ][ 'Gemstone' ];
  795.     }
  796.     if ($_POST[ 'data' ][ 'Center_stone' ]) {
  797.         $center_stone = $_POST[ 'data' ][ 'Center_stone' ];
  798.     }
  799.     $query_args = [
  800.         'post_type'   => 'product',
  801.         'post_status' => 'publish',
  802.         'meta_query'  => [
  803.             [         // restrict posts based on meta values
  804.                 'key'     => '_parent_prod',
  805.                 'value'   => $sku,
  806.                 'compare' => '='],
  807.         ],
  808.         'tax_query'   => [
  809.             [
  810.                 'taxonomy' => 'pa_ring-metal',
  811.                 'field'    => 'slug',
  812.                 'terms'    => $metal,
  813.             ],
  814.         ],
  815.     ];
  816.     if ($center_stone != '') {
  817.         $query_args[ 'tax_query' ] = [
  818.             'relation' => 'AND',
  819.             [
  820.                 'taxonomy' => 'pa_center-stone',
  821.                 'field'    => 'slug',
  822.                 'terms'    => $center_stone,
  823.             ],
  824.             [
  825.                 'taxonomy' => 'pa_ring-metal',
  826.                 'field'    => 'slug',
  827.                 'terms'    => $metal,
  828.             ],
  829.         ];
  830.     }
  831.     if ($Gemstone != '') {
  832.         $query_args[ 'tax_query' ] = [
  833.             'relation' => 'AND',
  834.             [
  835.                 'taxonomy' => 'pa_accent-stones',
  836.                 'field'    => 'slug',
  837.                 'terms'    => $Gemstone,
  838.             ],
  839.             [
  840.                 'taxonomy' => 'pa_ring-metal',
  841.                 'field'    => 'slug',
  842.                 'terms'    => $metal,
  843.             ],
  844.         ];
  845.     }
  846.     $query = new WP_QUERY($query_args);
  847.     while ($query->have_posts()):$query->the_post();
  848.         $link = get_permalink();
  849.     endwhile;
  850.     // не забываем завершать PHP
  851.     echo $link;
  852.     wp_die();
  853. }
  854.  
  855. //add_filter('show_admin_bar', '__return_false');
  856. //Store the custom field
  857. add_filter('woocommerce_add_cart_item_data', 'add_cart_item_custom_data_vase', 10, 2);
  858. function add_cart_item_custom_data_vase($cart_item_meta, $product_id)
  859. {
  860.     global $woocommerce;
  861.     if (isset($_POST[ 'select_country' ]))
  862.         $cart_item_meta[ 'select_country' ] = $_POST[ 'select_country' ];
  863.     if (isset($_POST[ 'select_s' ]))
  864.         $cart_item_meta[ 'select_s' ] = $_POST[ 'select_s' ];
  865.     if (isset($_POST[ 'certificate' ]))
  866.         $cart_item_meta[ 'certificate' ] = $_POST[ 'certificate' ];
  867.  
  868.     return $cart_item_meta;
  869. }
  870.  
  871. //Get it from the session and add it to the cart variable
  872. function get_cart_items_from_session($item, $values, $key)
  873. {
  874.     if (array_key_exists('select_country', $values))
  875.         $item[ 'Ring_Country' ] = $values[ 'select_country' ];
  876.     if (array_key_exists('select_s', $values))
  877.         $item[ 'Ring_Size' ] = $values[ 'select_s' ];
  878.     if (array_key_exists('certificate', $values))
  879.         $item[ 'Certificate' ] = $values[ 'certificate' ];
  880.  
  881.     return $item;
  882. }
  883.  
  884. add_filter('woocommerce_get_cart_item_from_session', 'get_cart_items_from_session', 1, 3);
  885.  
  886. function iconic_add_engraving_text_to_order_items( $item, $cart_item_key, $values, $order ) {
  887.     if ( !empty( $values['Ring_Country'] ) ) {
  888.         $item->add_meta_data( __( 'Ring Country', 'IconicJew' ), $values['Ring_Country'] );
  889.     }
  890.     if ( !empty( $values['Ring_Size'] ) ) {
  891.         $item->add_meta_data( __( 'Ring Size', 'IconicJew' ), $values['Ring_Size'] );
  892.     }
  893.     if ( !empty( $values['Certificate'] ) ) {
  894.         $item->add_meta_data( __( 'Certificate', 'IconicJew' ), $values['Certificate'] );
  895.     }
  896.    
  897. }
  898.  
  899. add_action( 'woocommerce_checkout_create_order_line_item', 'iconic_add_engraving_text_to_order_items', 10, 4 );
  900.  
  901. function so_validate_add_cart_item( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) {
  902.  
  903.     global $woocommerce;
  904.  
  905.     $option = 'select_s';
  906.  
  907.     // do your validation, if not met switch $passed to false
  908.  
  909.     if(get_post_meta($product_id, '_type_of_product', true) == 'Ring'){
  910.      if(!isset($_POST['select_s'])) {
  911.        $passed = false;
  912.    }
  913.   }
  914.     if (!$passed) {
  915.       wc_add_notice( __( 'You need to select size', 'textdomain' ), 'error' );
  916.  
  917.   }
  918.  
  919.  
  920.     return $passed;
  921.  
  922.  
  923. }
  924.  
  925. add_filter( 'woocommerce_add_to_cart_validation', 'so_validate_add_cart_item', 10, 5 );
  926.  
  927. function woocommerce_add_to_cart_validation_custom($passed, $product_id, $qty){
  928.  
  929.   global $woocommerce;
  930.  
  931.   $option = 'Ring_size'; // your custom field's name
  932.  
  933.  
  934.  
  935.   if (!$passed)
  936.     $woocommerce->add_error( sprintf( __('"%s" is a required field.', 'woocommerce'), $option) );
  937.  
  938.   return $passed;
  939.  
  940. }
  941.  
  942. add_action('wp_ajax_nopriv_load-search', 'prefix_load_search');
  943. add_action('wp_ajax_load-search', 'prefix_load_search');
  944.  
  945. function prefix_load_search()
  946. {
  947.     $search_string = sanitize_text_field($_POST[ 'search' ]);
  948.     $args = [
  949.         'post_type'      => 'product',
  950.         'post_status'    => 'published',
  951.         's'              => $search_string,
  952.         'posts_per_page' => 3,
  953.     ];
  954.  
  955.     $query = new WP_Query($args);
  956.  
  957.     ob_start();
  958.     echo '<ul>';
  959.     while ($query->have_posts()):$query->the_post();
  960.         $id = get_the_ID();
  961.         $product_wc = wc_get_product($id);
  962.         echo '<li data-url="' . get_permalink() . '">' .
  963.              '<div class="searchautocomlete-image">' .
  964.              get_the_post_thumbnail($id, [50, 50]) .
  965.              '</div>' .
  966.              '<a class="name highlight" href="' . get_permalink() . '">' . get_the_title() . '</a>' .
  967.              '<div class="price-box">' .
  968.              $product_wc->get_price_html() .
  969.              '</div>' .
  970.              '<div class="clearfix"></div>' .
  971.              '</li>';
  972.     endwhile;
  973.     echo '</ul>';
  974.     $response = ob_get_contents();
  975.     ob_end_clean();
  976.  
  977.     echo json_encode([
  978.         'data' => $response,
  979.     ]);
  980.     die(1);
  981. }
  982.  
  983. add_action('wp_ajax_nopriv_load-filter2', 'prefix_load_term_posts');
  984. add_action('wp_ajax_load-filter2', 'prefix_load_term_posts');
  985.  
  986. function prefix_load_term_posts()
  987. {
  988.     /*
  989.     $massive['relation'] = 'OR';
  990.     foreach($_POST['data'] as $data){
  991.         $massive[]=array(
  992.                 'taxonomy'=>$data['attr'],
  993.                 'field' => 'slug',
  994.                 'terms' => $data['slug']
  995.             );
  996.     }
  997.     $args = array(
  998.         'post_type' => 'product',
  999.         'post_status' => 'publish',
  1000.         'posts_per_page' =>(isset($_POST['per_page_n'])?$_POST['per_page_n']:32),
  1001.         'paged' => $_POST['page'],
  1002.         'tax_query'=>   array(
  1003.             'relation' => 'AND',
  1004.         array(
  1005.                         'taxonomy' => 'product_cat',
  1006.             'field' => 'id',
  1007.             'terms' => $_POST['category']
  1008.             ),
  1009.                     $massive
  1010.                 )
  1011.     );*/
  1012.     global $WOOCS;
  1013.     $currencies = $WOOCS->get_currencies();
  1014.     $cur_cur = $currencies[ $_POST[ 'curency' ] ][ 'rate' ];
  1015.     $massive = [];
  1016.     foreach ($_POST[ 'data' ] as $data) {
  1017.         $massive[ $data[ 'attr' ] ][] = [
  1018.             'taxonomy' => $data[ 'attr' ],
  1019.             'field'    => 'slug',
  1020.             'terms'    => $data[ 'slug' ],
  1021.         ];
  1022.         //if (count($massive[ $data[ 'attr' ] ]) == 2) {
  1023.         $massive[ $data[ 'attr' ] ][ 'relation' ] = 'OR';
  1024.         //}
  1025.     }
  1026.     if (array_key_exists('pa_center-stone', $massive) && array_key_exists('pa_accent-stones', $massive)) {
  1027.         $massive[ 'pa_center-stone' ] = array_merge($massive[ 'pa_center-stone' ], $massive[ 'pa_accent-stones' ]);
  1028.         unset($massive[ 'pa_accent-stones' ]);
  1029.     }
  1030.     $massive = array_values($massive);
  1031.     $tax_query = array_merge([
  1032.         'relation' => 'AND',
  1033.         [
  1034.             'taxonomy' => 'product_cat',
  1035.             'field'    => 'id',
  1036.             'terms'    => $_POST[ 'category' ],
  1037.         ]], $massive);
  1038.     $args = [
  1039.         'post_type'      => 'product',
  1040.         'post_status'    => 'publish',
  1041.         'posts_per_page' => (isset($_POST[ 'per_page_n' ]) ? $_POST[ 'per_page_n' ] : 32),
  1042.         'paged'          => $_POST[ 'page' ],
  1043.         'suppress_filters'=>false,
  1044.         'tax_query'      =>
  1045.             $tax_query,
  1046.     ];
  1047.  
  1048.     if ($_POST[ 'sort_by' ] == 'random_order') {
  1049.         $args[ 'orderby' ] = 'rand';
  1050.     }
  1051.     if ($_POST[ 'sort_by' ] == 'date') {
  1052.         $args[ 'orderby' ] = 'date';
  1053.     }
  1054.     if ($_POST[ 'sort_by' ] == 'price') {
  1055.         $args[ 'order' ] = 'ASC';
  1056.         $args[ 'orderby' ] = 'meta_value_num';
  1057.         $args[ 'meta_key' ] = '_price';
  1058.     }
  1059.     if ($_POST[ 'sort_by' ] == 'price-desc') {
  1060.         $args[ 'orderby' ] = 'meta_value_num';
  1061.         $args[ 'meta_key' ] = '_price';
  1062.     }
  1063.     if ($_POST[ 'sort_by' ] == 'popularity') {
  1064.         $args[ 'orderby' ] = 'total_sales';
  1065.     }
  1066.     if ($_POST[ 'priceT' ] || $_POST[ 'priceF' ]) {
  1067.         if ($_POST[ 'priceT' ]) {
  1068.             $max = intval($WOOCS->back_convert($_POST[ 'priceT' ], $cur_cur, 2));
  1069.  
  1070.         } else {
  1071.             $max = 99999999;
  1072.         }
  1073.         if ($_POST[ 'priceF' ]) {
  1074.             $min = intval($WOOCS->back_convert($_POST[ 'priceF' ], $cur_cur, 2));
  1075.         } else {
  1076.             $min = 0;
  1077.         }
  1078.         $args[ 'meta_query' ] = [
  1079.             'relation' => 'AND',
  1080.             [
  1081.                 'key'     => '_price',
  1082.                 'value'   => $min,
  1083.                 'compare' => '>=',
  1084.                 'type'    => 'DECIMAL',
  1085.             ],
  1086.             [
  1087.                 'key'     => '_price',
  1088.                 'value'   => $max,
  1089.                 'compare' => '<=',
  1090.                 'type'    => 'DECIMAL',
  1091.             ],
  1092.         ];
  1093.         // $args['meta_key']='_price';
  1094.         // $args['meta_value']=array($min,$max);
  1095.         // $args['meta_compare']='BETWEEN';
  1096.     }
  1097.     $query = new WP_QUERY($args);
  1098.     ob_start();
  1099.     while ($query->have_posts()): $query->the_post();
  1100.         wc_get_template_part('content', 'product');
  1101.     endwhile;
  1102.     $response = ob_get_contents();
  1103.     ob_end_clean();
  1104.  
  1105.     $paged = max(1, $query->get('paged'));
  1106.     $per_page = $query->get('posts_per_page');
  1107.     $total = $query->found_posts;
  1108.     $first = ($per_page * $paged) - $per_page + 1;
  1109.     $last = min($total, $query->get('posts_per_page') * $paged);
  1110.  
  1111.  
  1112.     /* translators: 1: first result 2: last result 3: total results */
  1113.     $count = sprintf('Showing <span id="showfrom"> 1 </span> to <span id="showto"> %2$d  </span> of <span id="showall"> %3$d </span> items', $first, $last, $total);
  1114.  
  1115.     $pagin = preg_replace('/ul/', 'ol', paginate_links(apply_filters('woocommerce_pagination_args', [
  1116.         'base'      => esc_url_raw(str_replace(999999999, '%#%', remove_query_arg('add-to-cart', get_pagenum_link(999999999, false)))),
  1117.         'format'    => '',
  1118.         'add_args'  => false,
  1119.         'current'   => max(1, $_POST[ 'page' ]),
  1120.         'total'     => $query->max_num_pages,
  1121.         'prev_text' => '&larr;',
  1122.         'next_text' => '&rarr;',
  1123.         'type'      => 'list',
  1124.         'end_size'  => 0,
  1125.         'mid_size'  => 2,
  1126.     ])));
  1127.     //echo $response;
  1128.  
  1129.     $from = (isset($_POST[ 'per_page_n' ]) ? $_POST[ 'per_page_n' ] : 32) * ($_POST[ 'page' ] - 1) + 1;
  1130.     if ($query->max_num_pages == $_POST[ 'page' ]) {
  1131.         $to = ($query->found_posts % (isset($_POST[ 'per_page_n' ]) ? $_POST[ 'per_page_n' ] : 32)) + $from - 1;
  1132.     } else {
  1133.         $to = (isset($_POST[ 'per_page_n' ]) ? $_POST[ 'per_page_n' ] : 32) * ($_POST[ 'page' ]);
  1134.     }
  1135.  
  1136.     echo json_encode(['count'   => $query->found_posts,
  1137.                       'data'    => $response,
  1138.                       'pagin'   => $pagin,
  1139.                       'from'    => $from,
  1140.                       'to'      => $to,
  1141.                       'args'    => $count,
  1142.                       'cur'     => $cur_cur,
  1143.                       'query'   => $query,
  1144.                       'min-max' => [$min, $max]]);
  1145.     die(1);
  1146. }
  1147.  
  1148.  
  1149. add_action('wp_head', 'remove_my_action');
  1150. function remove_my_action()
  1151. {
  1152.     remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination');
  1153.     add_action('woocommerce_after_shop_loop', 'woocommerce_result_count', 20);
  1154.     add_action('woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 30);
  1155.     remove_action('woocommerce_before_checkout_form', 'woocommerce_checkout_login_form');
  1156.     remove_action('woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form');
  1157.     remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20);
  1158.     add_action('woocommerce_checkout_payment_form', 'woocommerce_checkout_payment');
  1159.     //remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
  1160.     //add_action('woocommerce_checkout_shipping', 'woocommerce_checkout_coupon_form' , 30);
  1161.  
  1162. }
  1163.  
  1164. add_filter('woocommerce_checkout_fields', 'webendev_woocommerce_checkout_fields');
  1165. function webendev_woocommerce_checkout_fields($fields)
  1166. {
  1167.  
  1168.     $fields[ 'order' ][ 'order_comments' ][ 'placeholder' ] = __('Enter text to be engraved (up to 15 characters, standard numbers and letters only)','IconicJew');
  1169.     $fields[ 'order' ][ 'order_comments' ][ 'label' ] = __('Optional: Add Engraving','IconicJew');
  1170.  
  1171.     return $fields;
  1172. }
  1173.  
  1174. add_action('woocommerce_before_calculate_totals', 'sv_change_product_price_cart', 80, 1);
  1175. function sv_change_product_price_cart($cart_object)
  1176. {
  1177.  
  1178.     if (is_admin() && !defined('DOING_AJAX'))
  1179.         return;
  1180.  
  1181.     foreach ($cart_object->get_cart() as $cart_item) {
  1182.         if (isset($cart_item[ 'Certificate' ]) and ($cart_item[ 'Certificate' ] == 'on')) {
  1183.             $old_price = $cart_item[ 'data' ]->get_price();
  1184.             $price = $old_price + 30;
  1185.             $cart_item[ 'data' ]->set_price($price);
  1186.             $cart_item[ 'Certificate_2' ] = 'yes';
  1187.         }
  1188.  
  1189.     }
  1190. }
  1191.  
  1192. add_filter('wp_nav_menu_items', 'your_custom_menu_item', 10, 2);
  1193. function your_custom_menu_item($items, $args)
  1194. {
  1195.     if (is_object($args->menu) && ($args->menu->term_id == 1324)) {
  1196.         $items .= '<li><div data-id="cc28f4f859" class="livechat_button" style="display:inline; text-transform:capitalize;"><a href="http://www.livechatinc.com/customer-service-software/?partner=lc_2267311&amp;utm_source=chat_button"></a></div></li>';
  1197.     }
  1198.  
  1199.     return $items;
  1200. }
  1201.  
  1202. function drop_hint_message($prod_id, $name, $email, $message, $recipients)
  1203. {
  1204.  
  1205.     $product = wc_get_product($prod_id);
  1206.     $multiple_recipients = [get_option('admin_email')];
  1207.     foreach ($recipients as $recipient) {
  1208.         $multiple_recipients[] = $recipient[ 'email' ];
  1209.     }
  1210.  
  1211.     $subject = $product->get_title();
  1212.     $body = 'The email body content';
  1213.     $headers = ['Content-Type: text/html; charset=UTF-8', 'From: ' . $name . ' <' . $email . '>'];
  1214.  
  1215.     $action = wp_mail($multiple_recipients, $subject, $body, $headers);
  1216.  
  1217.     return $action;
  1218. }
  1219.  
  1220. function drop_hint_message_pop($prod_id, $name, $email, $recipient_name, $recipient_email)
  1221. {
  1222.  
  1223.     $product = wc_get_product($prod_id);
  1224.     $multiple_recipients = [get_option('admin_email'), $recipient_email];
  1225.  
  1226.     $subject = $product->get_title();
  1227.     $link = get_permalink($prod_id);
  1228.     $body = 'Dear ' . $recipient_name . ',<br><br>' .
  1229.             'The team at Iconic have found out ' . $name . ' hopes to empower women around the world.' .
  1230.             'This can only happen with your help. 100% of the profits from Iconic Jewellery supports women starting businesses,' .
  1231.             'going to school, leading their communities and building strong families.' .
  1232.             'Help make the gift even more special with our free engraving service.<br><br> ' .
  1233.             '<a href="' . $link . '">Discover the item here*</a>';
  1234.     $headers = ['Content-Type: text/html; charset=UTF-8', 'From: ' . $name . ' <' . $email . '>'];
  1235.  
  1236.     $action = wp_mail($multiple_recipients, $subject, $body, $headers);
  1237.  
  1238.     return $action;
  1239. }
  1240.  
  1241. add_action('wp_ajax_nopriv_drop-submit', 'prefix_drop_submit');
  1242. add_action('wp_ajax_drop-submit', 'prefix_drop_submit');
  1243.  
  1244. function prefix_drop_submit()
  1245. {
  1246.     $action = drop_hint_message_pop($_POST[ 'form' ][ 'prod_id' ], $_POST[ 'form' ][ 'sender_n' ], $_POST[ 'form' ][ 'sender_e' ], $_POST[ 'form' ][ 'recipient_n' ], $_POST[ 'form' ][ 'recipient_e' ]);
  1247.     if ($action) {
  1248.         $status = 'success';
  1249.         $message = 'Your email was sent successfully';
  1250.     } else {
  1251.         $status = 'failure';
  1252.         $message = 'There was an error trying to send your message. Please try again later.';
  1253.     }
  1254.     echo json_encode([
  1255.         'status'  => $status,
  1256.         'message' => $message]);
  1257.     die();
  1258. }
  1259.  
  1260. //function myplugin_wpml_ls_dirs_to_scan( $dirs ) {
  1261. //  $folder_name = basename( dirname( __FILE__ ) );
  1262. //  $dirs[]      = trailingslashit( WP_PLUGIN_DIR ) . $folder_name . '/templates/';
  1263. //  return $dirs;
  1264. //}
  1265. //add_filter( 'wpml_ls_directories_to_scan', 'myplugin_wpml_ls_dirs_to_scan' );
  1266.  
  1267. function icl_post_languages_2()
  1268. {
  1269.     //$languages = icl_get_languages('skip_missing=1');
  1270.     //if (1 < count($languages)) {
  1271.     //  echo "<select id=\"select-language\" title=\"Your Language\" onchange=\"window.location.href=this.value\">";
  1272.     //  foreach ($languages as $l) {
  1273.     //      if (!$l[ 'active' ]) {
  1274.     //          $langs[] = '<option value="' . $l[ 'url' ] . '">' . $l[ 'native_name' ] . '</option>';
  1275.     //      } else {
  1276.     //          $langs[] = '<option selected value="' . $l[ 'url' ] . '">' . $l[ 'native_name' ] . '</option>';
  1277.     //      }
  1278.     //  }
  1279. //
  1280.     //  echo join(', ', $langs);
  1281.     //  echo "</select>";
  1282.     //}
  1283. }
  1284.  
  1285. function sv_change_product_price_display($price)
  1286. {
  1287.     if (is_product()) {
  1288.         $price2 = str_replace_nth('<\/span>', ' </span><p class="in-store">'.__('In-Store Price','IconicJew').'</p> </span>', $price, 1);
  1289.         $price2 = str_replace_nth('amount\">', 'amount"><span>', $price2, 0);
  1290.  
  1291.         return str_replace_nth('<\/span>', ' <p class="in-store">'.__('Online Price','IconicJew').'</p></span> ', $price2, 4);
  1292.     }
  1293.  
  1294.     return $price;
  1295.  
  1296. }
  1297.  
  1298. function str_replace_nth($search, $replace, $subject, $nth)
  1299. {
  1300.     $found = preg_match_all('/' . $search . '/', $subject, $matches, PREG_OFFSET_CAPTURE);
  1301.     if (false !== $found && $found > $nth) {
  1302.         return substr_replace($subject, $replace, $matches[ 0 ][ $nth ][ 1 ], strlen($search) - 1);
  1303.     }
  1304.  
  1305.     return $subject;
  1306. }
  1307.  
  1308. add_filter('woocommerce_get_price_html', 'sv_change_product_price_display');
  1309.  
  1310. add_filter('woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby');
  1311. add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby');
  1312. function custom_woocommerce_catalog_orderby($sortby)
  1313. {
  1314.     $sortby[ 'random_order' ] = 'Random';
  1315.  
  1316.  
  1317.  
  1318.     return $sortby;
  1319. }
  1320. function sv_alphabetical_woocommerce_shop_ordering( $sort_args ) {
  1321.     $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
  1322.  
  1323.     if ( 'random_order' == $orderby_value ) {
  1324.         $sort_args['orderby'] = 'rand';
  1325.     }
  1326.  
  1327.     return $sort_args;
  1328. }
  1329. add_filter( 'woocommerce_get_catalog_ordering_args', 'sv_alphabetical_woocommerce_shop_ordering' );
  1330.  
  1331. function get_original_cf($postid = 0, $element_type = 'post', $key)
  1332. {
  1333.     global $sitepress, $post;
  1334.  
  1335.     $postid = ($postid == 0 ? $post->ID : $postid);
  1336.     $custom_field = get_post_meta(icl_object_id($postid, $element_type, false, $sitepress->get_default_language()), $key, true);
  1337.  
  1338.     return $custom_field;
  1339. }
  1340.  
  1341. add_action('woocommerce_product_query', 'test_query');
  1342.  
  1343. function test_query($query)
  1344. {
  1345.     if (is_product_category()) {
  1346.         $query->query = ['product_cat' => $query->query[ 'product_cat' ]];
  1347.  
  1348.         if (array_key_exists(0,$query->tax_query->queries)){
  1349.             $query->tax_query->queries = [$query->tax_query->queries[ 0 ]];
  1350.         }
  1351.         if (array_key_exists(0,$query->tax_query->queried_terms)){
  1352.             $query->tax_query->queried_terms = [$query->tax_query->queried_terms[ 0 ]];
  1353.         }
  1354.  
  1355.         $qv = $query->query_vars;
  1356.         foreach ($_GET as $key => $value) {
  1357.             unset($qv[ $key ]);
  1358.         }
  1359.  
  1360.         $query->query_vars = $qv;
  1361.     }
  1362.  
  1363.     return $query;
  1364. }
  1365.  
  1366. function isa_comment_reform ($arg) {
  1367.     $arg['title_reply'] = __('Leave a review :');
  1368.     return $arg;
  1369. }
  1370. add_filter('comment_form_defaults','isa_comment_reform');
  1371.  
  1372.  
  1373.  
  1374. function alx_html_js_class () {
  1375.     echo '<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>'. "\n";
  1376. }
  1377. add_action( 'wp_head', 'alx_html_js_class', 1 );
  1378.  
  1379.  
  1380. function cc_mime_types($mimes) {
  1381.     $mimes['svg'] = 'image/svg+xml';
  1382.     return $mimes;
  1383. }
  1384. add_filter('upload_mimes', 'cc_mime_types');
  1385.  
  1386. function jewellery_jewelry($attr) {
  1387.         return '<span style="text-transform:'.$attr['style'].'">'.strtolower(HOME_TITLE).'</span>';
  1388. }
  1389. add_shortcode( 'jewellery', 'jewellery_jewelry' );
  1390.  
  1391.  
  1392. add_filter('wpseo_title','change_in_titles');
  1393.  
  1394. function change_in_titles($string){
  1395.     if(HOME_TITLE=='JEWELLERY'){
  1396.         $string = str_replace('Jewelry','Jewellery',$string);
  1397.     }
  1398.     else{
  1399.         $string = str_replace('Jewellery','Jewelry',$string);
  1400.     }
  1401.     return $string;
  1402. }
  1403. function my_get_the_product_thumbnail_url( $size = 'shop_catalog' ) {
  1404.     global $post;
  1405.     $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size );
  1406.     return get_the_post_thumbnail_url( $post->ID, $image_size );
  1407. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement