plugin_name = $plugin_name; $this->version = $version; add_action( 'wp_ajax_wt_crp_ajax_attribute_search', array( $this, 'wt_crp_ajax_attribute_search' ) ); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/custom-related-products-admin.css', array( 'wc-admin-layout' ), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { if ( isset( $_GET['page'] ) && 'wt-woocommerce-related-products' === $_GET['page'] && current_user_can( 'manage_options' ) ) { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/custom-related-products-admin.js', array( 'jquery' ), $this->version, false ); } } /** * Add related products selector to edit product section */ function crp_select_related_products() { global $post, $woocommerce; $settings_url = admin_url( '/admin.php?page=wt-woocommerce-related-products' ); $working_mode = Custom_Related_Products::get_current_working_mode(); if ( $working_mode != 'custom' ) { ?>

', '' ); ?>

ID, '_crp_related_product_attr', true ); ?>

ID, '_crp_related_ids', true ) ) ); ?> version >= '2.3' && $woocommerce->version < '3.0' ) : ?>

crp_insert_scripts(); $this->crp_insert_styles(); } /** * Load JavaScript functions on product edit screen */ function crp_insert_scripts() { ?> version >= '2.3' && $woocommerce->version < '3.0' ) { $related = $custom_related_ids; } else { $related = array(); $ids = $custom_related_ids; foreach ( $ids as $id ) { if ( $id && $id > 0 ) { $related[] = $id; } } } update_post_meta( $post_id, '_crp_related_ids', $related ); } else { delete_post_meta( $post_id, '_crp_related_ids' ); } // save related categories if ( isset( $_POST['crp_related_product_cats'] ) && current_user_can( 'manage_woocommerce' ) ) { $custom_related_product_cat_id = ( isset( $_POST['crp_related_product_cats'] ) && is_array( $_POST['crp_related_product_cats'] ) ) ? array_map( 'absint', $_POST['crp_related_product_cats'] ) : array(); if ( $woocommerce->version >= '2.3' && $woocommerce->version < '3.0' ) { $related = $custom_related_product_cat_id; } else { $related = array(); $ids = $custom_related_product_cat_id; foreach ( $ids as $id ) { if ( $id && $id > 0 ) { $related[] = $id; } } } update_post_meta( $post_id, '_crp_related_product_cats', $related ); } else { delete_post_meta( $post_id, '_crp_related_product_cats' ); } // save related tags if ( isset( $_POST['crp_related_product_tags'] ) && current_user_can( 'manage_woocommerce' ) ) { $custom_related_product_tag_id = ( isset( $_POST['crp_related_product_tags'] ) && is_array( $_POST['crp_related_product_tags'] ) ) ? array_map( 'absint', $_POST['crp_related_product_tags'] ) : array(); if ( $woocommerce->version >= '2.3' && $woocommerce->version < '3.0' ) { $related = $custom_related_product_tag_id; } else { $related = array(); $ids = $custom_related_product_tag_id; foreach ( $ids as $id ) { if ( $id && $id > 0 ) { $related[] = $id; } } } update_post_meta( $post_id, '_crp_related_product_tags', $related ); } else { delete_post_meta( $post_id, '_crp_related_product_tags' ); } // save related attributes if ( isset( $_POST['crp_related_product_attr'] ) && current_user_can( 'manage_woocommerce' ) ) { $crp_related_atts_data = isset( $_POST['crp_related_product_attr'] ) ? Wt_Related_Product_Security_Helper::crp_sanitize_text( $_POST['crp_related_product_attr'] ) : array(); $crp_related_atts_data = $this->process_related_attr_data( $crp_related_atts_data ); update_post_meta( $post_id, '_crp_related_product_attr', $crp_related_atts_data ); } else { delete_post_meta( $post_id, '_crp_related_product_attr' ); } // save excluded categories if ( isset( $_POST['crp_exclude_cats'] ) && current_user_can( 'manage_woocommerce' ) ) { $custom_related_product_cat_id = ( isset( $_POST['crp_exclude_cats'] ) && is_array( $_POST['crp_exclude_cats'] ) ) ? array_map( 'absint', $_POST['crp_exclude_cats'] ) : array(); if ( $woocommerce->version >= '2.3' && $woocommerce->version < '3.0' ) { $related = $custom_related_product_cat_id; } else { $related = array(); $ids = $custom_related_product_cat_id; foreach ( $ids as $id ) { if ( $id && $id > 0 ) { $related[] = $id; } } } update_post_meta( $post_id, '_crp_excluded_cats', $related ); } else { delete_post_meta( $post_id, '_crp_excluded_cats' ); } } public function add_options_page() { $this->plugin_screen_hook_suffix = add_submenu_page( 'woocommerce', __( 'Related Products for WooCommerce', 'wt-woocommerce-related-products' ), __( 'Related Products', 'wt-woocommerce-related-products' ), apply_filters( 'woocommerce_custom_related_products_role', 'manage_woocommerce' ), $this->plugin_name, array( $this, 'display_options_page' ) ); add_action( 'wt_crp_before_settings_block', array( $this, 'crp_display_branding' ) ); } public function display_options_page() { $tab = 'related-product'; if ( ! empty( $_GET['tab'] ) ) { if ( $_GET['tab'] == 'other-solutions' ) { $tab = 'other-solutions'; } elseif ( $_GET['tab'] == 'related-product' ) { $tab = 'related-product'; } } include_once 'partials/custom-related-products-admin-tab-view.php'; } /** * Admin Page for exporting */ public function admin_related_product_page() { include_once 'partials/custom-related-products-admin-display.php'; } /** * Admin Page for exporting */ public function admin_other_solution_page() { include_once 'partials/admin-settings-other-solutions.php'; } public function register_setting() { add_settings_section( $this->option_name . '_general', '', array( $this, $this->option_name . '_general_cb' ), $this->plugin_name ); add_settings_field( $this->option_name . '_working_mode', __( 'Working mode', 'wt-woocommerce-related-products' ), array( $this, $this->option_name . '_working_mode_cb' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_working_mode' ), ); add_settings_field( $this->option_name . '_cart_working_mode', __( 'Show related products in cart', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Enable to display the related products recommendation on the cart page.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_cart_working_mode_cb' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_cart_working_mode', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_field( $this->option_name . '_slider', __( 'Slider', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Turn on the product slider to allow customers to browse related products by swiping left or right.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_slider_cb' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_slider', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_field( $this->option_name . '_crp_banner_product_width', __( 'Number of products to display on slider per page', 'wt-woocommerce-related-products' ), array( $this, $this->option_name . '_crp_banner_product_width' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_crp_banner_product_width', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_field( $this->option_name . '_crp_number', __( 'Number of products to display', 'wt-woocommerce-related-products' ) . wc_help_tip( sprintf( __( 'Choose the number of products to display as related products. This number must be greater than the %1$sNumber of products to display on the slider per page%2$s for the slider to function correctly. The default value is 4.', 'wt-woocommerce-related-products' ), '', '' ) ), array( $this, $this->option_name . '_crp_number' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_crp_number', 'class' => 'crp-tr-field mode-default-disallow wt-slider-mode', ), ); add_settings_field( $this->option_name . '_crp_banner_width', __( 'Slider width', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Alter the width of the related product section.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_banner_width' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_crp_banner_width', 'class' => 'crp-tr-field mode-default-disallow wt-slider-mode', ), ); add_settings_field( $this->option_name . '_crp_custom_slider_arrow', __( 'Use custom slider arrow', 'wt-woocommerce-related-products' ), array( $this, $this->option_name . '_crp_custom_slider_arrow' ), $this->plugin_name, $this->option_name . '_general', array( 'label_for' => $this->option_name . '_crp_custom_slider_arrow', 'class' => 'crp-tr-field mode-default-disallow wt-slider-mode', ), ); add_settings_section( $this->option_name . '_widget_settings', '', array( $this, $this->option_name . '_widget_settings_cb' ), $this->plugin_name, array( 'class' => 'wt-pr-settings' ) ); add_settings_field( $this->option_name . '_crp_title', __( 'Related products title', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'The entered text will be displayed as the title of related products recommendation on the store.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_title' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_title', 'class' => 'crp-tr-field', ), ); add_settings_field( $this->option_name . '_crp_related_by', __( 'Display related products from', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Based on the selection made, products from the same category and tag will be shown as recommendations.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_related_by' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_related_by', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_field( $this->option_name . '_crp_exclude_widget_category', __( 'Hide related products for categories', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Select which categories should be excluded from displaying related products.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_exclude_widget_category' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_exclude_widget_category', 'class' => 'crp-tr-field mode-default-disallow wt-gloablly-relate crp-child', ), ); add_settings_field( $this->option_name . '_crp_exclude_widget_product', __( 'Hide related products for products', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Select individual products that should not display related products.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_exclude_widget_product' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_exclude_widget_product', 'class' => 'crp-tr-field mode-default-disallow wt-gloablly-relate crp-child', ), ); add_settings_field( $this->option_name . '_crp_linked_products_banner', '', array( $this, $this->option_name . '_crp_linked_products_banner' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_linked_products_banner', 'class' => 'crp-tr-field crp-linked-products-banner mode-default-disallow', ), ); add_settings_field( $this->option_name . '_crp_order_by', __( 'Sort by', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Select the criteria for sorting related products.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_order_by' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_order_by', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_field( $this->option_name . '_crp_order', __( 'Sort order', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Choose whether to sort related products in ascending (A-Z, low to high) or descending (Z-A, high to low) order based on the selected criteria.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_crp_order' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_crp_order', 'class' => 'crp-tr-field mode-default-disallow', ), ); // add_settings_field( // $this->option_name . '_slider_type', __( 'Choose slider type', 'wt-woocommerce-related-products'), array($this, $this->option_name . '_slider_type'), $this->plugin_name, $this->option_name . '_general', array('label_for' => $this->option_name . '_slider_type', // 'class' => 'crp-tr-field mode-default-disallow wt-slider-mode') // ); add_settings_field( $this->option_name . '_exclude_os', __( 'Exclude out of stock products', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Enable to exclude out of stock products from being displayed as related product recommendations.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_exclude_os_cb' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_exclude_os', 'class' => 'crp-tr-field mode-default-disallow', ), ); // Exclude Backorder products add_settings_field( $this->option_name . '_rp_exclude_backorder', __( 'Exclude Backorder products', 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Enable to exclude backorder products from being displayed as related product recommendations.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_rp_exclude_backorder' ), $this->plugin_name, $this->option_name . '_widget_settings', array( 'label_for' => $this->option_name . '_rp_exclude_backorder', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_section( $this->option_name . '_advanced_settings', '', array( $this, $this->option_name . '_advanced_settings_cb' ), $this->plugin_name ); add_settings_field( $this->option_name . '_use_primary_id_wpml', __( 'Use original product ID(WPML)', 'wt-woocommerce-related-products' ), array( $this, $this->option_name . '_use_primary_id_wpml_cb' ), $this->plugin_name, $this->option_name . '_advanced_settings', array( 'label_for' => $this->option_name . '_use_primary_id_wpml', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_field( $this->option_name . '_overide_theme_rp', __( "Override theme's template", 'wt-woocommerce-related-products' ) . wc_help_tip( __( 'Enable to override the theme’s existing template for related products.', 'wt-woocommerce-related-products' ) ), array( $this, $this->option_name . '_overide_theme_rp_cb' ), $this->plugin_name, $this->option_name . '_advanced_settings', array( 'label_for' => $this->option_name . '_overide_theme_rp', 'class' => 'crp-tr-field mode-default-disallow', ), ); add_settings_section( $this->option_name . '_info_bottom', '', array( $this, $this->option_name . '_info_bottom_cb' ), $this->plugin_name ); register_setting( $this->plugin_name, $this->option_name . '_working_mode' ); register_setting( $this->plugin_name, $this->option_name . '_cart_working_mode' ); register_setting( $this->plugin_name, $this->option_name . '_disable' ); register_setting( $this->plugin_name, $this->option_name . '_disable_custom' ); register_setting( $this->plugin_name, $this->option_name . '_crp_title' ); register_setting( $this->plugin_name, $this->option_name . '_crp_related_by' ); register_setting( $this->plugin_name, $this->option_name . '_crp_exclude_widget_category' ); register_setting( $this->plugin_name, $this->option_name . '_crp_exclude_widget_product' ); register_setting( $this->plugin_name, $this->option_name . '_crp_order_by' ); register_setting( $this->plugin_name, $this->option_name . '_crp_order' ); register_setting( $this->plugin_name, $this->option_name . '_crp_number' ); register_setting( $this->plugin_name, $this->option_name . '_crp_banner_width' ); register_setting( $this->plugin_name, $this->option_name . '_crp_custom_slider_arrow' ); register_setting( $this->plugin_name, $this->option_name . '_crp_banner_product_width' ); register_setting( $this->plugin_name, $this->option_name . '_exclude_os' ); // Exclude backorder register_setting( $this->plugin_name, $this->option_name . '_rp_exclude_backorder' ); register_setting( $this->plugin_name, $this->option_name . '_slider' ); // register_setting( // $this->plugin_name, $this->option_name . '_slider_type' // ); register_setting( $this->plugin_name, $this->option_name . '_use_primary_id_wpml' ); register_setting( $this->plugin_name, $this->option_name . '_overide_theme_rp', array( 'default' => 'enable' ) ); add_action( 'admin_head', array( $this, 'insert_main_settings_scripts' ), 999 ); } public function custom_related_products_working_mode_cb() { $working_mode = Custom_Related_Products::get_current_working_mode(); ?>
>

>

>

option_name . '_crp_title', __( 'Related Products', 'wt-woocommerce-related-products' ) ); ?>
option_name . '_crp_banner_width', __( '100', 'wt-woocommerce-related-products' ) ); ?>

option_name . '_crp_banner_product_width' ); $desktop_view = isset( $crp_view_port[0] ) && ! empty( $crp_view_port[0] ) ? $crp_view_port[0] : 3; $tab_view = isset( $crp_view_port[1] ) && ! empty( $crp_view_port[1] ) ? $crp_view_port[1] : 2; $mobile_view = isset( $crp_view_port[2] ) && ! empty( $crp_view_port[2] ) ? $crp_view_port[2] : 1; $desktop_view_default = isset( $crp_view_port[3] ) && ! empty( $crp_view_port[3] ) ? $crp_view_port[3] : 5; $tab_view_default = isset( $crp_view_port[4] ) && ! empty( $crp_view_port[4] ) ? $crp_view_port[4] : 2; $mobile_view_default = isset( $crp_view_port[5] ) && ! empty( $crp_view_port[5] ) ? $crp_view_port[5] : 1; ?>

plugin_url() . '/assets/css/admin.css' ); } $crp_related_by = (array) get_option( $this->option_name . '_crp_related_by', array( 'category' ) ); ?>
  1. > >
option_name . '_crp_order_by', 'popularity' ); ?>
option_name . '_crp_order', 'DESC' ); ?>
option_name . '_crp_number', 10 ); ?>

option_name . '_exclude_os' ); ?>
option_name . '_rp_exclude_backorder' ); ?>
option_name . '_slider', 'enable' ); ?>
option_name . '_slider_type', 'swiper' ); ?>

', '' ); ?>

', '' ); ?>

option_name . '_use_primary_id_wpml' ); ?>

', '' ); ?>

option_name . '_overide_theme_rp' ); ?>
', '', '', '' ); ?>

' . __( 'Settings', 'wt-woocommerce-related-products' ) . '', '' . __( 'Documentation', 'wt-woocommerce-related-products' ) . '', '' . __( 'Support', 'wt-woocommerce-related-products' ) . '', '' . __( 'Review', 'wt-woocommerce-related-products' ) . '', ); if ( array_key_exists( 'deactivate', $links ) ) { $links['deactivate'] = str_replace( ' '' . esc_html__( 'Support', 'wt-woocommerce-related-products' ) . '', 'export' => '' . esc_html__( 'Export', 'wt-woocommerce-related-products' ) . '', 'import' => '' . esc_html__( 'Import', 'wt-woocommerce-related-products' ) . '', ); return array_merge( $links, $row_meta ); } /** * Insert scripts for the main settings page * * @since 1.3.9 * @return void */ public function insert_main_settings_scripts() { $slide_width = get_option( 'custom_related_products_crp_banner_width' ) ? get_option( 'custom_related_products_crp_banner_width' ) : 300; ?> 'pa_' . $attr->attribute_name, 'hide_empty' => false, ) ); foreach ( $terms as $term ) { $attributes_list[] = array( 'id' => $attr->attribute_name . ':' . $term->term_id, 'text' => $attr->attribute_label . ':' . $term->name, ); } } } wp_send_json( apply_filters( 'wt_json_search_found_attrs', $attributes_list ) ); } /** * process related attribute data before storing to db * * @since 1.4.0 * @return array */ public function process_related_attr_data( $related_attr ) { $attr_data = array(); foreach ( $related_attr as $attr ) { $exploded = explode( ':', $attr ); if ( ! empty( $exploded[0] ) && ! empty( $exploded[1] ) ) { $attr_data[ $exploded[0] ][] = $exploded[1]; } } return $attr_data; } /** * Display branding section * * @since 1.4.1 * @return void */ public function crp_display_branding() { $webtoffee_logo_url = CRP_PLUGIN_URL . 'admin/img/wt_logo.png'; ?>
modules as $module ) { $module_file = plugin_dir_path( __FILE__ ) . "modules/$module/$module.php"; if ( file_exists( $module_file ) ) { self::$existing_modules[] = $module; // this is for module_exits checking require_once $module_file; } } } /** * Option for Custom slider Arrow * * @since 1.5.1 */ public function custom_related_products_crp_custom_slider_arrow() { $crp_custom_slider_arrow = get_option( $this->option_name . '_crp_custom_slider_arrow' ); ?>