Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Your Inspiration Themes
- *
- * @package WordPress
- * @subpackage Your Inspiration Themes
- * @author Your Inspiration Themes Team <info@yithemes.com>
- *
- * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://www.gnu.org/licenses/gpl-3.0.txt
- */
- add_action( 'wp_enqueue_scripts', 'yit_enqueue_parent_theme_style' );
- if ( ! function_exists( 'yit_enqueue_parent_theme_style' ) ) {
- /**
- * enqueue the parent css file
- *
- *
- * @return void
- * @since 1.0.0
- * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
- */
- function yit_enqueue_parent_theme_style() {
- wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' , array( 'bootstrap-twitter' ));
- if ( function_exists( 'yit_set_wc_template_path' ) ) {
- wp_enqueue_style( 'woocommerce-parent-style', get_template_directory_uri() . '/' . yit_set_wc_template_path( 'woocommerce' ) . '/style.css' );
- }
- }
- }
- add_action( 'after_setup_theme', 'yit_child_theme_setup' );
- if ( ! function_exists( 'yit_child_theme_setup' ) ) {
- /**
- * load child language files
- *
- *
- * @return void
- * @since 1.0.0
- * @author Andrea Frascaspata <andrea.frascaspata@yithemes.com>
- */
- function yit_child_theme_setup() {
- load_child_theme_textdomain( 'yit', get_stylesheet_directory() . '/languages' );
- }
- }
- if( function_exists('YITH_Frontend_Manager') && function_exists( 'yith_wcfm_get_main_page_url' ) ) {
- add_action('yith_wcmap_before_endpoints_items', 'yith_frontend_manager_add_menu');
- function yith_frontend_manager_add_menu()
- {
- if (YITH_Frontend_Manager()->current_user_can_manage_woocommerce_on_front()) {
- $menu_title = apply_filters('yith-wcfm-my-account-menu-text', __('Seller dashboard', 'yith-frontend-manager-for-woocommerce'));
- $menu_link = yith_wcfm_get_main_page_url();
- echo '<li class=""><a href="' . $menu_link . '"><i class="fa fa-laptop" aria-hidden="true"></i><span>' . $menu_title . '</span></a></li>';
- }
- }
- }
- remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
- add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 21 );
- function gd_bypass_logout_confirmation() {
- global $wp;
- if ( isset( $wp->query_vars['customer-logout'] ) ) {
- wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
- exit;
- }
- }
- add_action( 'template_redirect', 'gd_bypass_logout_confirmation' );
- function wc_login_redirect( $redirect_to ) {
- $usr = wp_get_current_user();
- $roles = $usr->roles;
- if ( $roles[0] != 'vendor' ) {
- $redirect_to = home_url();
- }
- return $redirect_to;
- }
- add_filter('woocommerce_login_redirect', 'wc_login_redirect');
- if(!function_exists('yith_wcdn_url_suborder')) {
- function yith_wcdn_url_suborder($url,$suborder_id,$order) {
- error_log(print_r("AQUI ESTOY",true));
- if(function_exists('yith_wcfm_order_url')) {
- error_log(print_r("Aqui Estamos",true));
- $new_url = yith_wcfm_order_url(false, false, $suborder_id);
- error_log(print_r($new_url,true));
- return $new_url;
- }
- return $url;
- }
- add_filter('yith_wcdn_url_suborder', 'yith_wcdn_url_suborder',10,3);
- }
- /* -------------------- Vendors page ---------------------------- */
- if ( ! function_exists( 'yith_add_vendors_custom_filter_shortcode' ) ) {
- function yith_add_vendors_custom_filter_shortcode() {
- ob_start();
- ?>
- <script>
- console.log('yith-here');
- jQuery(document).ready(function ($) {
- var nores = $('#noresults'),
- vendor = $(".vendor-item");
- // search for vendors
- $('input#search-for-vendors').on('keyup change', function (e) {
- nores.hide();
- var filter = $(this).val(), count = 0;
- vendor.each(function () {
- if ($(this).find('h3 a').text().search(new RegExp(filter, "i")) < 0) {
- $(this).fadeOut();
- } else {
- count++;
- $(this).fadeIn();
- }
- });
- if (count == 0) {
- nores.fadeIn();
- }
- });
- });
- </script>
- <div class="search-for">
- <input type="text" id="search-for-vendors" placeholder="Search Vendors...">
- </div>
- <div style="display:none" id="noresults"><p>Sorry, no vendors matching your terms...</p></div>
- <?php
- return ob_get_clean();
- }
- add_shortcode( 'yith_add_vendors_custom_filter_shortcode', 'yith_add_vendors_custom_filter_shortcode' );
- }
- /* ------------------------------- END of vendors page ------------------------------------------*/
- /*-------------------------------- External and grouped product disable---------------------------*/
- if( function_exists( 'YITH_Vendors' ) ){
- add_filter( 'product_type_selector', 'yith_wcmv_product_type_selector', 20 );
- if( ! function_exists( 'yith_wcmv_product_type_selector' ) ){
- function yith_wcmv_product_type_selector( $types ){
- $vendor = yith_get_vendor( 'current', 'user' );
- if( $vendor->is_valid() && $vendor->has_limited_access() ){
- if( isset( $types['external'] ) ){
- unset($types['external']);
- }
- if( isset( $types['grouped'] ) ){
- unset($types['grouped']);
- }
- }
- return $types;
- }
- }
- }
- /*-------------------------------- External and grouped product disable END ---------------------------*/
- /*-------------------------------- Link in product filter ---------------------------*/
- function filters_add_links() {
- ?>
- <script type="text/javascript" charset="utf-8">
- jQuery(document).ready(function($) {
- /* shoe size filter */
- $('#yith-woo-ajax-navigation-4 ul').prepend('<a href="http://shop.ostein.at/shoe-size-chart/">Shoe Sizes Chart</a>');
- /* clothing size filter */
- $('#yith-woo-ajax-navigation-7 ul').prepend('<a href="http://shop.ostein.at/clothing-size-chart/">Clothing Sizes Chart</a>');
- });
- </script>
- <?php
- }
- add_action( 'wp_head', 'filters_add_links' );
- /*-------------------------------- END of Link in product filter ---------------------------*/
- /*-------------------------------- Disable shipping coupon ---------------------------*/
- add_filter( 'woocommerce_shipping_instance_form_fields_free_shipping', 'yith_woocommerce_shipping_instance_form_fields_free_shipping' );
- if( ! function_exists( 'yith_woocommerce_shipping_instance_form_fields_free_shipping' ) ){
- function yith_woocommerce_shipping_instance_form_fields_free_shipping( $form_fields ){
- if( ! empty( $form_fields['requires']['options'] ) ){
- foreach( array('coupon', 'either', 'both' ) as $field ){
- if( isset( $form_fields['requires']['options'][ $field ] ) ){
- unset( $form_fields['requires']['options'][ $field ] );
- }
- }
- }
- return $form_fields;
- }
- }
- /*---------------------------- END of Disable shipping coupon -----------------------*/
- /*---------------------------- Disable pending review -----------------------*/
- add_filter( 'yith_wcfm_allowed_product_status', 'yith_wcfm_allowed_product_status', 20 );
- if( ! function_exists( 'yith_wcfm_allowed_product_status' ) ){
- function yith_wcfm_allowed_product_status( $status ){
- if( isset( $status['pending'] ) ){
- unset( $status['pending'] );
- }
- return $status;
- }
- }
- /*---------------------------- END of Disable pending review -----------------------*/
- /*---------------------------- Disable CSV product import -----------------------*/
- add_action( 'yith_wcfm_products_enqueue_scripts', 'yith_wcfm_add_custom_script', 20 );
- if ( ! function_exists( 'yith_wcfm_add_custom_script' ) ) {
- function yith_wcfm_add_custom_script() {
- $css = '.yith-wcfm-section-products .woocommerce-BlankState .woocommerce-BlankState-cta:last-of-type{display: none;}';
- $css_handle = 'yith-wcfm-products';
- wp_add_inline_style( $css_handle, $css );
- $js = "jQuery('.woocommerce-BlankState').find('.woocommerce-BlankState-cta:last-of-type').remove();";
- $js_handle = 'yith-frontend-manager-product-js';
- wp_add_inline_script( $js_handle, $js );
- }
- }
- /*---------------------------- END of Disable CSV product import -----------------------*/
- /*---------------------------- Shipping method local pickup disable -----------------------*/
- add_filter( 'woocommerce_shipping_methods', 'yith_remove_local_pickup', 10, 1 );
- function yith_remove_local_pickup($methods) {
- unset( $methods['local_pickup'] );
- return $methods;
- }
- /*---------------------------- END of Shipping method local pickup disable -----------------------*/
- //add_action( 'wp_enqueue_scripts', 'yith_wcfm_custom_js_for_variations',999999999999 );
- function yith_wcfm_custom_js_for_variations(){
- 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'));
- }
- /*---------------------------- Adding product variation "Learn more" link -----------------------*/
- add_filter( 'woocommerce_docs_url', 'my_woocommerce_docs_url' );
- function my_woocommerce_docs_url() {
- if ( ! defined( ICL_LANGUAGE_CODE ) || ICL_LANGUAGE_CODE == 'en' ) {
- 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
- } else if ( ICL_LANGUAGE_CODE == 'lv' ) {
- return 'http://shop.ostein.at/how-to-add-a-product/#1519722604630-2d048025-7646/lv';
- } else if ( ICL_LANGUAGE_CODE == 'es' ) {
- return 'http://shop.ostein.at/how-to-add-a-product/#1519722604630-2d048025-7646/es';
- }
- }
- /*---------------------------- END of Adding product variation "Learn more" link -----------------------*/
- /*---------------------------- Delete Shipping costs message when adding product -----------------------*/
- add_action('template_redirect','yith_customize_shipping_panel_for_vendors');
- function yith_customize_shipping_panel_for_vendors(){
- global $yith_wc_product_shipping_admin;
- if( function_exists( 'YITH_Vendors' ) ){
- $vendor = yith_get_vendor( 'current', 'user' );
- if( $vendor->is_valid() && $vendor->has_limited_access() ){
- remove_action( 'woocommerce_product_data_panels', array( $yith_wc_product_shipping_admin, 'product_shipping_panel' ) );
- add_action( 'woocommerce_product_data_panels', 'yith_custom_product_shipping_panel');
- }
- }
- }
- function yith_custom_product_shipping_panel(){
- global $woocommerce, $post, $yith_wc_product_shipping_admin ?>
- <div id="yith_woocommerce_product_shipping" class="panel woocommerce_options_panel">
- <?php
- if ( yith_wcps_is_wcfm() ) {
- $post_id = $_GET['product_id'];
- $post = get_post( $post_id );
- }
- woocommerce_wp_checkbox(
- array(
- 'id' => '_yith_product_shipping',
- 'label' => __( 'Enable Shipping Costs', 'yith-product-shipping-for-woocommerce' ),
- 'description' => '',
- )
- );
- $yith_wc_product_shipping_admin->shipping_table();
- ?>
- </div>
- <?php
- }
- /*---------------------------- END of Delete Shipping costs message when adding product -----------------------*/
- /*---------------------------- Duplicate front end products -----------------------*/
- add_action('wp_footer', 'my_duplicate_on_insert');
- function my_duplicate_on_insert() {
- // Create post object
- $my_post = array(
- 'post_title' => 'My post to insert from the front-end',
- 'post_content' => 'This is my post.',
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_category' => array(1)
- );
- // Insert the post into the database
- $post_id = wp_insert_post( $my_post );
- if ( $post_id ) {
- do_action( 'wpml_make_post_duplicates', $post_id );
- }
- }
- /*---------------------------- END of Duplicate front end products -----------------------*/
- /*---------------------------- Duplicate back end products -----------------------*/
- add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
- function my_duplicate_on_publish( $post_id ) {
- global $post;
- // don't save for autosave
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // dont save for revisions
- if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
- return $post_id;
- }
- // we need this to avoid recursion see add_action at the end
- remove_action( 'wp_insert_post', 'my_duplicate_on_publish' );
- // make duplicates if the post being saved
- // #1. itself is not a duplicate of another or
- // #2. does not already have translations
- $is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
- if ( !$is_translated ) {
- do_action( 'wpml_admin_make_post_duplicates', $post_id );
- }
- // must hook again - see remove_action further up
- add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
- }
- /*---------------------------- END of Duplicate back end products -----------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement