Advertisement
Guest User

Untitled

a guest
Oct 4th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.86 KB | None | 0 0
  1. <?php
  2. /**
  3. * Your Inspiration Themes
  4. *
  5. * @package WordPress
  6. * @subpackage Your Inspiration Themes
  7. * @author Your Inspiration Themes Team <info@yithemes.com>
  8. *
  9. * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
  10. * that is bundled with this package in the file LICENSE.txt.
  11. * It is also available through the world-wide-web at this URL:
  12. * http://www.gnu.org/licenses/gpl-3.0.txt
  13. */
  14.  
  15. add_action( 'wp_enqueue_scripts', 'yit_enqueue_parent_theme_style' );
  16.  
  17. if ( ! function_exists( 'yit_enqueue_parent_theme_style' ) ) {
  18. /**
  19. * enqueue the parent css file
  20. *
  21. *
  22. * @return void
  23. * @since 1.0.0
  24. * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
  25. */
  26. function yit_enqueue_parent_theme_style() {
  27. wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' , array( 'bootstrap-twitter' ));
  28. if ( function_exists( 'yit_set_wc_template_path' ) ) {
  29. wp_enqueue_style( 'woocommerce-parent-style', get_template_directory_uri() . '/' . yit_set_wc_template_path( 'woocommerce' ) . '/style.css' );
  30. }
  31. }
  32. }
  33.  
  34.  
  35.  
  36. add_action( 'after_setup_theme', 'yit_child_theme_setup' );
  37.  
  38. if ( ! function_exists( 'yit_child_theme_setup' ) ) {
  39. /**
  40. * load child language files
  41. *
  42. *
  43. * @return void
  44. * @since 1.0.0
  45. * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
  46. */
  47. function yit_child_theme_setup() {
  48. load_child_theme_textdomain( 'yit', get_stylesheet_directory() . '/languages' );
  49. }
  50. }
  51. if( function_exists('YITH_Frontend_Manager') && function_exists( 'yith_wcfm_get_main_page_url' ) ) {
  52. add_action('yith_wcmap_before_endpoints_items', 'yith_frontend_manager_add_menu');
  53.  
  54. function yith_frontend_manager_add_menu()
  55. {
  56. if (YITH_Frontend_Manager()->current_user_can_manage_woocommerce_on_front()) {
  57. $menu_title = apply_filters('yith-wcfm-my-account-menu-text', __('Seller dashboard', 'yith-frontend-manager-for-woocommerce'));
  58. $menu_link = yith_wcfm_get_main_page_url();
  59.  
  60. echo '<li class=""><a href="' . $menu_link . '"><i class="fa fa-laptop" aria-hidden="true"></i><span>' . $menu_title . '</span></a></li>';
  61. }
  62. }
  63. }
  64. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
  65. add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 21 );
  66. function gd_bypass_logout_confirmation() {
  67. global $wp;
  68.  
  69. if ( isset( $wp->query_vars['customer-logout'] ) ) {
  70. wp_redirect( str_replace( '&amp;', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
  71. exit;
  72. }
  73. }
  74.  
  75. add_action( 'template_redirect', 'gd_bypass_logout_confirmation' );
  76. function wc_login_redirect( $redirect_to ) {
  77. $usr = wp_get_current_user();
  78. $roles = $usr->roles;
  79. if ( $roles[0] != 'vendor' ) {
  80. $redirect_to = home_url();
  81. }
  82.  
  83. return $redirect_to;
  84. }
  85. add_filter('woocommerce_login_redirect', 'wc_login_redirect');
  86.  
  87. if(!function_exists('yith_wcdn_url_suborder')) {
  88. function yith_wcdn_url_suborder($url,$suborder_id,$order) {
  89. error_log(print_r("AQUI ESTOY",true));
  90. if(function_exists('yith_wcfm_order_url')) {
  91. error_log(print_r("Aqui Estamos",true));
  92. $new_url = yith_wcfm_order_url(false, false, $suborder_id);
  93. error_log(print_r($new_url,true));
  94. return $new_url;
  95. }
  96. return $url;
  97. }
  98. add_filter('yith_wcdn_url_suborder', 'yith_wcdn_url_suborder',10,3);
  99. }
  100.  
  101. /* -------------------- Vendors page ---------------------------- */
  102.  
  103.  
  104. if ( ! function_exists( 'yith_add_vendors_custom_filter_shortcode' ) ) {
  105. function yith_add_vendors_custom_filter_shortcode() {
  106. ob_start();
  107.  
  108. ?>
  109. <script>
  110. console.log('yith-here');
  111. jQuery(document).ready(function ($) {
  112. var nores = $('#noresults'),
  113. vendor = $(".vendor-item");
  114. // search for vendors
  115. $('input#search-for-vendors').on('keyup change', function (e) {
  116. nores.hide();
  117. var filter = $(this).val(), count = 0;
  118.  
  119. vendor.each(function () {
  120. if ($(this).find('h3 a').text().search(new RegExp(filter, "i")) < 0) {
  121. $(this).fadeOut();
  122. } else {
  123. count++;
  124. $(this).fadeIn();
  125. }
  126. });
  127.  
  128. if (count == 0) {
  129. nores.fadeIn();
  130. }
  131. });
  132. });
  133. </script>
  134. <div class="search-for">
  135. <input type="text" id="search-for-vendors" placeholder="Search Vendors...">
  136. </div>
  137.  
  138. <div style="display:none" id="noresults"><p>Sorry, no vendors matching your terms...</p></div>
  139.  
  140. <?php
  141. return ob_get_clean();
  142.  
  143. }
  144.  
  145. add_shortcode( 'yith_add_vendors_custom_filter_shortcode', 'yith_add_vendors_custom_filter_shortcode' );
  146. }
  147.  
  148.  
  149. /* ------------------------------- END of vendors page ------------------------------------------*/
  150.  
  151.  
  152.  
  153.  
  154. /*-------------------------------- External and grouped product disable---------------------------*/
  155.  
  156. if( function_exists( 'YITH_Vendors' ) ){
  157. add_filter( 'product_type_selector', 'yith_wcmv_product_type_selector', 20 );
  158. if( ! function_exists( 'yith_wcmv_product_type_selector' ) ){
  159. function yith_wcmv_product_type_selector( $types ){
  160. $vendor = yith_get_vendor( 'current', 'user' );
  161. if( $vendor->is_valid() && $vendor->has_limited_access() ){
  162. if( isset( $types['external'] ) ){
  163. unset($types['external']);
  164. }
  165.  
  166. if( isset( $types['grouped'] ) ){
  167. unset($types['grouped']);
  168. }
  169. }
  170. return $types;
  171. }
  172. }
  173. }
  174.  
  175. /*-------------------------------- External and grouped product disable END ---------------------------*/
  176.  
  177.  
  178. /*-------------------------------- Link in product filter ---------------------------*/
  179.  
  180. function filters_add_links() {
  181. ?>
  182. <script type="text/javascript" charset="utf-8">
  183. jQuery(document).ready(function($) {
  184. /* shoe size filter */
  185. $('#yith-woo-ajax-navigation-4 ul').prepend('<a href="http://shop.ostein.at/shoe-size-chart/">Shoe Sizes Chart</a>');
  186. /* clothing size filter */
  187. $('#yith-woo-ajax-navigation-7 ul').prepend('<a href="http://shop.ostein.at/clothing-size-chart/">Clothing Sizes Chart</a>');
  188.  
  189. });
  190. </script>
  191. <?php
  192.  
  193. }
  194. add_action( 'wp_head', 'filters_add_links' );
  195.  
  196. /*-------------------------------- END of Link in product filter ---------------------------*/
  197.  
  198.  
  199. /*-------------------------------- Disable shipping coupon ---------------------------*/
  200.  
  201. add_filter( 'woocommerce_shipping_instance_form_fields_free_shipping', 'yith_woocommerce_shipping_instance_form_fields_free_shipping' );
  202. if( ! function_exists( 'yith_woocommerce_shipping_instance_form_fields_free_shipping' ) ){
  203. function yith_woocommerce_shipping_instance_form_fields_free_shipping( $form_fields ){
  204. if( ! empty( $form_fields['requires']['options'] ) ){
  205. foreach( array('coupon', 'either', 'both' ) as $field ){
  206. if( isset( $form_fields['requires']['options'][ $field ] ) ){
  207. unset( $form_fields['requires']['options'][ $field ] );
  208. }
  209. }
  210. }
  211.  
  212. return $form_fields;
  213. }
  214. }
  215.  
  216. /*---------------------------- END of Disable shipping coupon -----------------------*/
  217.  
  218.  
  219. /*---------------------------- Disable pending review -----------------------*/
  220.  
  221. add_filter( 'yith_wcfm_allowed_product_status', 'yith_wcfm_allowed_product_status', 20 );
  222.  
  223. if( ! function_exists( 'yith_wcfm_allowed_product_status' ) ){
  224. function yith_wcfm_allowed_product_status( $status ){
  225. if( isset( $status['pending'] ) ){
  226. unset( $status['pending'] );
  227. }
  228. return $status;
  229. }
  230. }
  231.  
  232. /*---------------------------- END of Disable pending review -----------------------*/
  233.  
  234.  
  235. /*---------------------------- Disable CSV product import -----------------------*/
  236.  
  237. add_action( 'yith_wcfm_products_enqueue_scripts', 'yith_wcfm_add_custom_script', 20 );
  238.  
  239. if ( ! function_exists( 'yith_wcfm_add_custom_script' ) ) {
  240. function yith_wcfm_add_custom_script() {
  241. $css = '.yith-wcfm-section-products .woocommerce-BlankState .woocommerce-BlankState-cta:last-of-type{display: none;}';
  242. $css_handle = 'yith-wcfm-products';
  243. wp_add_inline_style( $css_handle, $css );
  244.  
  245. $js = "jQuery('.woocommerce-BlankState').find('.woocommerce-BlankState-cta:last-of-type').remove();";
  246. $js_handle = 'yith-frontend-manager-product-js';
  247. wp_add_inline_script( $js_handle, $js );
  248. }
  249. }
  250.  
  251. /*---------------------------- END of Disable CSV product import -----------------------*/
  252.  
  253.  
  254. /*---------------------------- Shipping method local pickup disable -----------------------*/
  255.  
  256. add_filter( 'woocommerce_shipping_methods', 'yith_remove_local_pickup', 10, 1 );
  257. function yith_remove_local_pickup($methods) {
  258. unset( $methods['local_pickup'] );
  259. return $methods;
  260. }
  261.  
  262. /*---------------------------- END of Shipping method local pickup disable -----------------------*/
  263.  
  264.  
  265. //add_action( 'wp_enqueue_scripts', 'yith_wcfm_custom_js_for_variations',999999999999 );
  266.  
  267. function yith_wcfm_custom_js_for_variations(){
  268. wp_enqueue_script('yith_wcfm_js_for_variations', get_stylesheet_directory_uri() . '/assets/js/yith-wcfm-custom.js',array('jquery','wc-admin-product-meta-boxes','wc-admin-variation-meta-boxes'));
  269. }
  270.  
  271. /*---------------------------- Adding product variation "Learn more" link -----------------------*/
  272.  
  273. add_filter( 'woocommerce_docs_url', 'my_woocommerce_docs_url' );
  274.  
  275. function my_woocommerce_docs_url() {
  276.  
  277. if ( ! defined( ICL_LANGUAGE_CODE ) || ICL_LANGUAGE_CODE == 'en' ) {
  278.  
  279. return 'http://shop.ostein.at/how-to-add-a-product/#1519722604630-2d048025-7646'; // STANDARD URL FOR EN LANGUAGE AND ALSO IF WPML IS NOT ENABLED
  280.  
  281. } else if ( ICL_LANGUAGE_CODE == 'lv' ) {
  282.  
  283. return 'http://shop.ostein.at/how-to-add-a-product/#1519722604630-2d048025-7646/lv';
  284.  
  285. } else if ( ICL_LANGUAGE_CODE == 'es' ) {
  286.  
  287. return 'http://shop.ostein.at/how-to-add-a-product/#1519722604630-2d048025-7646/es';
  288.  
  289. }
  290.  
  291. }
  292.  
  293. /*---------------------------- END of Adding product variation "Learn more" link -----------------------*/
  294.  
  295.  
  296. /*---------------------------- Delete Shipping costs message when adding product -----------------------*/
  297.  
  298. add_action('template_redirect','yith_customize_shipping_panel_for_vendors');
  299.  
  300. function yith_customize_shipping_panel_for_vendors(){
  301. global $yith_wc_product_shipping_admin;
  302. if( function_exists( 'YITH_Vendors' ) ){
  303. $vendor = yith_get_vendor( 'current', 'user' );
  304. if( $vendor->is_valid() && $vendor->has_limited_access() ){
  305. remove_action( 'woocommerce_product_data_panels', array( $yith_wc_product_shipping_admin, 'product_shipping_panel' ) );
  306. add_action( 'woocommerce_product_data_panels', 'yith_custom_product_shipping_panel');
  307. }
  308. }
  309.  
  310. }
  311.  
  312. function yith_custom_product_shipping_panel(){
  313. global $woocommerce, $post, $yith_wc_product_shipping_admin ?>
  314. <div id="yith_woocommerce_product_shipping" class="panel woocommerce_options_panel">
  315. <?php
  316.  
  317. if ( yith_wcps_is_wcfm() ) {
  318. $post_id = $_GET['product_id'];
  319. $post = get_post( $post_id );
  320. }
  321.  
  322. woocommerce_wp_checkbox(
  323. array(
  324. 'id' => '_yith_product_shipping',
  325. 'label' => __( 'Enable Shipping Costs', 'yith-product-shipping-for-woocommerce' ),
  326. 'description' => '',
  327. )
  328. );
  329.  
  330. $yith_wc_product_shipping_admin->shipping_table();
  331.  
  332. ?>
  333. </div>
  334. <?php
  335. }
  336.  
  337. /*---------------------------- END of Delete Shipping costs message when adding product -----------------------*/
  338.  
  339.  
  340. /*---------------------------- Duplicate front end products -----------------------*/
  341.  
  342. add_action('wp_footer', 'my_duplicate_on_insert');
  343. function my_duplicate_on_insert() {
  344. // Create post object
  345. $my_post = array(
  346. 'post_title' => 'My post to insert from the front-end',
  347. 'post_content' => 'This is my post.',
  348. 'post_status' => 'publish',
  349. 'post_author' => 1,
  350. 'post_category' => array(1)
  351. );
  352.  
  353. // Insert the post into the database
  354. $post_id = wp_insert_post( $my_post );
  355. if ( $post_id ) {
  356. do_action( 'wpml_make_post_duplicates', $post_id );
  357. }
  358. }
  359.  
  360. /*---------------------------- END of Duplicate front end products -----------------------*/
  361.  
  362. /*---------------------------- Duplicate back end products -----------------------*/
  363.  
  364. add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
  365. function my_duplicate_on_publish( $post_id ) {
  366. global $post;
  367. // don't save for autosave
  368. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  369. return $post_id;
  370. }
  371. // dont save for revisions
  372. if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
  373. return $post_id;
  374. }
  375.  
  376. // we need this to avoid recursion see add_action at the end
  377. remove_action( 'wp_insert_post', 'my_duplicate_on_publish' );
  378.  
  379. // make duplicates if the post being saved
  380. // #1. itself is not a duplicate of another or
  381. // #2. does not already have translations
  382.  
  383. $is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
  384.  
  385. if ( !$is_translated ) {
  386. do_action( 'wpml_admin_make_post_duplicates', $post_id );
  387. }
  388.  
  389. // must hook again - see remove_action further up
  390. add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
  391. }
  392.  
  393. /*---------------------------- END of Duplicate back end products -----------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement