get_section( 'woocommerce_checkout' )->panel = 'ocean_woocommerce_panel'; $wp_customize->get_section( 'woocommerce_store_notice' )->panel = 'ocean_woocommerce_panel'; $wp_customize->get_section( 'woocommerce_product_images' )->panel = 'ocean_woocommerce_panel'; $wp_customize->get_section( 'woocommerce_product_images' )->priority = 999; $wp_customize->get_control( 'woocommerce_shop_page_display' )->section = 'ocean_woocommerce_archives'; $wp_customize->get_control( 'woocommerce_category_archive_display' )->section = 'ocean_woocommerce_archives'; $wp_customize->get_control( 'woocommerce_default_catalog_orderby' )->section = 'ocean_woocommerce_archives'; $wp_customize->get_control( 'woocommerce_checkout_company_field' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'woocommerce_checkout_address_2_field' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'woocommerce_checkout_phone_field' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'woocommerce_checkout_highlight_required_fields' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'wp_page_for_privacy_policy' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'woocommerce_terms_page_id' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'woocommerce_checkout_privacy_policy_text' )->section = 'ocean_woocommerce_checkout'; $wp_customize->get_control( 'woocommerce_checkout_terms_and_conditions_checkbox_text' )->section = 'ocean_woocommerce_checkout'; } /** * Content wrapper. * * @since 1.4.7 */ public static function content_wrapper() { get_template_part( 'woocommerce/wc-content-wrapper' ); } /** * Content wrapper end. * * @since 1.4.7 */ public static function content_wrapper_end() { get_template_part( 'woocommerce/wc-content-wrapper-end' ); } /** * Register new WooCommerce sidebar. * * @since 1.0.0 */ public static function register_woo_sidebar() { // Return if custom sidebar disabled if ( ! get_theme_mod( 'ocean_woo_custom_sidebar', true ) ) { return; } // Register new woo_sidebar widget area register_sidebar( array ( 'name' => esc_html__( 'WooCommerce Sidebar', 'oceanwp' ), 'id' => 'woo_sidebar', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); } /** * Display WooCommerce sidebar. * * @since 1.0.0 */ public static function display_woo_sidebar( $sidebar ) { // Alter sidebar display to show woo_sidebar where needed if ( get_theme_mod( 'ocean_woo_custom_sidebar', true ) && is_active_sidebar( 'woo_sidebar' ) && is_woocommerce() ) { $sidebar = 'woo_sidebar'; } // Return correct sidebar return $sidebar; } /** * Tweaks the post layouts for WooCommerce archives and single product posts. * * @since 1.0.0 */ public static function layouts( $class ) { if ( oceanwp_is_woo_shop() || oceanwp_is_woo_tax() ) { $class = get_theme_mod( 'ocean_woo_shop_layout', 'left-sidebar' ); } elseif ( oceanwp_is_woo_single() ) { $class = get_theme_mod( 'ocean_woo_product_layout', 'left-sidebar' ); } return $class; } /** * Set correct both sidebars layout style. * * @since 1.4.0 */ public static function bs_class( $class ) { if ( oceanwp_is_woo_shop() || oceanwp_is_woo_tax() ) { $class = get_theme_mod( 'ocean_woo_shop_both_sidebars_style', 'scs-style' ); } elseif ( oceanwp_is_woo_single() ) { $class = get_theme_mod( 'ocean_woo_product_both_sidebars_style', 'scs-style' ); } return $class; } /** * Set correct mobile sidebar order. * * @since 1.6 */ public static function sidebar_order( $order ) { if ( oceanwp_is_woo_shop() || oceanwp_is_woo_tax() ) { $order = get_theme_mod( 'ocean_woo_shop_sidebar_order', 'content-sidebar' ); } elseif ( oceanwp_is_woo_single() ) { $order = get_theme_mod( 'ocean_woo_product_sidebar_order', 'content-sidebar' ); } return $order; } /** * Mini cart style. * * @since 1.0.0 */ public static function mini_cart_style() { // Register WooCommerce styles wp_enqueue_style( 'oceanwp-woo-mini-cart', OCEANWP_CSS_DIR_URI .'woo/woo-mini-cart.min.css' ); // If rtl if ( is_RTL() ) { wp_enqueue_style( 'oceanwp-woo-mini-cart-rtl', OCEANWP_CSS_DIR_URI .'woo/woo-mini-cart-rtl.css' ); } } /** * Runs on Init. * You can't remove certain actions in the constructor because it's too early. * * @since 1.0.0 */ public function init() { // Remove WooCommerce breadcrumbs remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 ); // Alter upsells display remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 ); if ( '0' != get_theme_mod( 'ocean_woocommerce_upsells_count', '3' ) ) { add_action( 'woocommerce_after_single_product_summary', array( $this, 'upsell_display' ), 15 ); } // Alter cross-sells display remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' ); if ( '0' != get_theme_mod( 'ocean_woocommerce_cross_sells_count', '2' ) ) { add_action( 'woocommerce_cart_collaterals', array( $this, 'cross_sell_display' ) ); } // Add product thumbnail if ( 'hover' != get_theme_mod( 'ocean_woo_products_style', 'default' ) ) { add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'loop_product_thumbnail' ), 10 ); } // Remove related products if is set to no if ( 'on' != get_theme_mod( 'ocean_woocommerce_display_related_items', 'on' ) ) { remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); } // Remove orderby if disabled if ( ! get_theme_mod( 'ocean_woo_shop_sort', true ) ) { remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); } // Add result count if not disabled if ( get_theme_mod( 'ocean_woo_shop_result_count', true ) ) { add_action( 'woocommerce_before_shop_loop', array( $this, 'result_count' ), 31 ); } if ( defined( 'ELEMENTOR_WOOSTORE__FILE__' ) ) { remove_action( 'woocommerce_after_shop_loop_item_title', 'woostore_output_product_excerpt', 35 ); add_action( 'woocommerce_after_shop_loop_item', 'woostore_output_product_excerpt', 21 ); } if ( ! function_exists( 'yith_wcbm_shop_badge_container_start' ) && ! function_exists( 'yith_wcbm_shop_badge_container_end' ) ) { add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'yith_wcbm_shop_badge_container_start' ), 9 ); add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'yith_wcbm_shop_badge_container_end' ), 20 ); } if ( class_exists( 'WooCommerce_Germanized' ) ) { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_gzd_template_single_shipping_costs_info', 7 ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_gzd_template_single_tax_info', 6 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_gzd_template_single_legal_info', 12 ); add_action( 'ocean_after_archive_product_inner', array( $this, 'woocommerce_germanized' ) ); add_action( 'ocean_after_single_product_price', 'woocommerce_gzd_template_single_legal_info' ); } } /** * Remove elemnts. * * @since 1.0.0 */ public function remove_elements() { remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 ); remove_action( 'woocommerce_after_shop_loop_item','woocommerce_template_loop_product_link_close', 5 ); remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 ); remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); } /** * Fix the issue in the Elementor Pro editor. * * @since 1.5.19 */ public function before_template_part( $template_name, $template_path, $located, $args ) { if ( class_exists( 'Elementor\Plugin' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { self::remove_elements(); } } /** * Pagination. * * @since 1.4.16 */ public function shop_pagination() { if ( 'infinite_scroll' == get_theme_mod( 'ocean_woo_pagination_style', 'standard' ) ) { remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); add_action( 'woocommerce_after_shop_loop', array( $this, 'infinite_pagination' ), 10 ); } } /** * Infinite scroll pagination. * * @since 1.4.16 */ public static function infinite_pagination() { global $wp_query; if ( $wp_query->max_num_pages <= 1 ) { return; } // Load infinite scroll script wp_enqueue_script( 'infinitescroll' ); // Last text $last = get_theme_mod( 'ocean_woo_infinite_scroll_last_text' ); $last = oceanwp_tm_translation( 'ocean_woo_infinite_scroll_last_text', $last ); $last = $last ? $last: esc_html__( 'End of content', 'oceanwp' ); // Error text $error = get_theme_mod( 'ocean_woo_infinite_scroll_error_text' ); $error = oceanwp_tm_translation( 'ocean_woo_infinite_scroll_error_text', $error ); $error = $error ? $error: esc_html__( 'No more pages to load', 'oceanwp' ); // Output pagination HTML ?>

max_num_pages ); ?>
$val ) { if ( isset( $val['id'] ) && in_array( $val['id'], $remove ) ) { unset( $settings[$key] ); } } return $settings; } /** * Remove product settings from Woo Admin panel. * * @since 1.0.0 */ public static function remove_product_settings( $settings ) { $remove = array( 'woocommerce_enable_lightbox' ); foreach( $settings as $key => $val ) { if ( isset( $val['id'] ) && in_array( $val['id'], $remove ) ) { unset( $settings[$key] ); } } return $settings; } /** * Body classes * * @since 1.5.0 */ public static function body_class( $classes ) { // If dropdown categories widget style if ( 'dropdown' == get_theme_mod( 'ocean_woo_cat_widget_style', 'default' ) ) { $classes[] = 'woo-dropdown-cat'; } // Distraction free class if ( ( is_cart() && true == get_theme_mod( 'ocean_woo_distraction_free_cart', false ) ) || ( is_checkout() && true == get_theme_mod( 'ocean_woo_distraction_free_checkout', false ) ) ) { $classes[] = 'distraction-free'; } // My Account page style $style = get_theme_mod( 'ocean_woo_account_page_style', 'original' ); if ( 'side' == $style ) { $classes[] = 'account-side-style'; } else { $classes[] = 'account-original-style'; } // Return return $classes; } /** * Add Custom WooCommerce scripts. * * @since 1.0.0 */ public static function add_custom_scripts() { // Register WooCommerce styles wp_enqueue_style( 'oceanwp-woocommerce', OCEANWP_CSS_DIR_URI .'woo/woocommerce.min.css' ); wp_enqueue_style( 'oceanwp-woo-star-font', OCEANWP_CSS_DIR_URI .'woo/woo-star-font.min.css' ); // If rtl if ( is_RTL() ) { wp_enqueue_style( 'oceanwp-woocommerce-rtl', OCEANWP_CSS_DIR_URI .'woo/woocommerce-rtl.css' ); } // If products hover style if ( 'hover' == get_theme_mod( 'ocean_woo_products_style', 'default' ) ) { wp_enqueue_style( 'oceanwp-woo-hover-style', OCEANWP_CSS_DIR_URI .'woo/hover-style.min.css' ); wp_enqueue_script( 'oceanwp-woo-hover-style', OCEANWP_JS_DIR_URI .'third/woo/woo-hover-style.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If dropdown category widget style if ( 'dropdown' == get_theme_mod( 'ocean_woo_cat_widget_style', 'default' ) ) { wp_enqueue_script( 'oceanwp-woo-cat-widget', OCEANWP_JS_DIR_URI .'third/woo/woo-cat-widget.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If vertical thumbnails style if ( 'vertical' == get_theme_mod( 'ocean_woo_product_thumbs_layout', 'horizontal' ) ) { wp_enqueue_script( 'oceanwp-woo-thumbnails', OCEANWP_JS_DIR_URI .'third/woo/woo-thumbnails.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If quick view if ( get_theme_mod( 'ocean_woo_quick_view', true ) ) { wp_enqueue_script( 'oceanwp-woo-quick-view', OCEANWP_JS_DIR_URI .'third/woo/woo-quick-view.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); wp_enqueue_style( 'oceanwp-woo-quick-view', OCEANWP_CSS_DIR_URI .'woo/woo-quick-view.min.css' ); wp_enqueue_script( 'wc-add-to-cart-variation' ); wp_enqueue_script( 'flexslider' ); } // If whislist if ( class_exists( 'TInvWL_Wishlist' ) ) { wp_enqueue_style( 'oceanwp-wishlist', OCEANWP_CSS_DIR_URI .'woo/wishlist.min.css' ); } // If single product ajax add to cart if ( true == get_theme_mod( 'ocean_woo_product_ajax_add_to_cart', false ) && oceanwp_is_woo_single() ) { wp_enqueue_script( 'oceanwp-woo-ajax-addtocart', OCEANWP_JS_DIR_URI .'third/woo/woo-ajax-add-to-cart.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If floating bar if ( 'on' == get_theme_mod( 'ocean_woo_display_floating_bar', 'on' ) && oceanwp_is_woo_single() ) { wp_enqueue_style( 'oceanwp-woo-floating-bar', OCEANWP_CSS_DIR_URI .'woo/woo-floating-bar.min.css' ); wp_enqueue_script( 'oceanwp-woo-floating-bar', OCEANWP_JS_DIR_URI .'third/woo/woo-floating-bar.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If display cart when product added if ( 'yes' == get_theme_mod( 'ocean_woo_display_cart_product_added', 'no' ) ) { wp_enqueue_script( 'oceanwp-woo-display-cart', OCEANWP_JS_DIR_URI .'third/woo/woo-display-cart.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If off canvas filter if ( true == get_theme_mod( 'ocean_woo_off_canvas_filter', false ) && ( oceanwp_is_woo_shop() || oceanwp_is_woo_tax() ) ) { wp_enqueue_script( 'oceanwp-woo-off-canvas', OCEANWP_JS_DIR_URI .'third/woo/woo-off-canvas.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If mobile menu mini cart if ( get_theme_mod( 'ocean_woo_add_mobile_mini_cart', true ) ) { wp_enqueue_script( 'oceanwp-woo-mini-cart', OCEANWP_JS_DIR_URI .'third/woo/woo-mini-cart.min.js', array( 'jquery' ), OCEANWP_THEME_VERSION, true ); } // If multi step checkout if ( true == get_theme_mod( 'ocean_woo_multi_step_checkout', false ) && is_checkout() ) { wp_enqueue_style( 'oceanwp-woo-multistep-checkout', OCEANWP_CSS_DIR_URI .'woo/woo-multistep-checkout.min.css' ); $woo_deps = array( 'jquery', 'wc-checkout', 'wc-country-select' ); if ( class_exists( 'WC_Ship_Multiple' ) ){ $woo_deps[] = 'wcms-country-select'; } wp_enqueue_script( 'oceanwp-woo-multistep-checkout', OCEANWP_JS_DIR_URI .'third/woo/woo-multistep-checkout.min.js', $woo_deps, OCEANWP_THEME_VERSION, true ); } } /** * Localize array. * * @since 1.5.0 */ public static function localize_array( $array ) { // If single product ajax add to cart if ( true == get_theme_mod( 'ocean_woo_product_ajax_add_to_cart', false ) ) { $array['is_cart'] = is_cart(); $array['cart_url'] = apply_filters( 'ocean_woocommerce_add_to_cart_redirect', wc_get_cart_url() ); } // If multi step checkout if ( true == get_theme_mod( 'ocean_woo_multi_step_checkout', false ) ) { $array['ajax_url'] = admin_url( 'admin-ajax.php' ); $array['login_reminder_enabled'] = 'yes' == get_option( 'woocommerce_enable_checkout_login_reminder', 'yes' ) ? true : false; $array['is_logged_in'] = is_user_logged_in(); $array['no_account_btn'] = esc_html__( 'I don’t have an account', 'oceanwp' ); $array['next'] = esc_html__( 'Next', 'oceanwp' ); } // If quick view, ajax add to cart or floating bar if ( get_theme_mod( 'ocean_woo_quick_view', true ) || true == get_theme_mod( 'ocean_woo_product_ajax_add_to_cart', false ) || 'on' == get_theme_mod( 'ocean_woo_display_floating_bar', 'on' ) ) { $array['ajax_url'] = admin_url( 'admin-ajax.php' ); $array['cart_url'] = apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url(), null ); $array['cart_redirect_after_add'] = get_option( 'woocommerce_cart_redirect_after_add' ); } // Add the View Cart here to avoid the undefined word on the related products $array['view_cart'] = esc_html__( 'View cart', 'oceanwp' ); // Check if the floating bar is enabled for the quantity button $array['floating_bar'] = get_theme_mod( 'ocean_woo_display_floating_bar', 'on' ); // Grouped product button text in the quick view $array['grouped_text'] = esc_attr__( 'View products', 'oceanwp' ); return $array; } /** * Single Product add to cart ajax request. * * @since 1.5.0 */ public static function add_cart_single_product_ajax() { $product_id = sanitize_text_field( $_POST['product_id'] ); $variation_id = sanitize_text_field( $_POST['variation_id'] ); $variation = $_POST['variation']; $quantity = sanitize_text_field( $_POST['quantity'] ); if ( $variation_id ) { WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation ); } else { WC()->cart->add_to_cart( $product_id, $quantity ); } die(); } /** * Add cart overlay. * * @since 1.5.0 */ public static function cart_overlay() { ?>
'; echo '
'; echo '×'; echo '

'. esc_html__( 'Cart', 'oceanwp' ) .'

'; echo '
'; the_widget( 'WC_Widget_Cart', 'title=' ); echo '
'; echo '
'; echo '
'; echo ''; } /** * Adds an opening div "oceanwp-toolbar" around top elements. * * @since 1.1.1 */ public static function add_shop_loop_div() { echo '
'; } /** * Register off canvas filter sidebar. * * @since 1.5.0 */ public static function register_off_canvas_sidebar() { register_sidebar( array ( 'name' => esc_html__( 'Off-Canvas Filters', 'oceanwp' ), 'description' => esc_html__( 'Widgets in this area are used in the off canvas sidebar. To enable the Off Canvas filter, go to the WooCommerce > Archives section of the customizer and enable the Display Filter Button option.', 'oceanwp' ), 'id' => 'owp_off_canvas_sidebar', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); } /** * Get Off Canvas Sidebar. * * @since 1.5.0 */ public static function get_off_canvas_sidebar() { // Return if is not in shop page if ( ! oceanwp_is_woo_shop() && ! oceanwp_is_woo_tax() ) { return; } if ( function_exists( 'wc_get_template' ) ) { wc_get_template( 'owp-off-canvas-sidebar.php' ); } } /** * Add off canvas filter button. * * @since 1.5.0 */ public static function off_canvas_filter_button() { // Return if is not in shop page if ( ! oceanwp_is_woo_shop() && ! oceanwp_is_woo_tax() ) { return; } // Get filter text $text = get_theme_mod( 'ocean_woo_off_canvas_filter_text' ); $text = oceanwp_tm_translation( 'ocean_woo_off_canvas_filter_text', $text ); $text = $text ? $text: esc_html__( 'Filter', 'oceanwp' ); $output = ''. esc_html( $text ) .''; echo apply_filters( 'oceanwp_off_canvas_filter_button_output', $output ); } /** * Add grid/list buttons. * * @since 1.1.1 */ public static function grid_list_buttons() { // Return if is not in shop page if ( ! oceanwp_is_woo_shop() && ! oceanwp_is_woo_tax() ) { return; } // Titles $grid_view = esc_html__( 'Grid view', 'oceanwp' ); $list_view = esc_html__( 'List view', 'oceanwp' ); // Active class if ( 'list' == get_theme_mod( 'ocean_woo_catalog_view', 'grid' ) ) { $list = 'active '; $grid = ''; } else { $grid = 'active '; $list = ''; } $output = sprintf( '', esc_html( $grid_view ), esc_attr( $grid ), esc_html( $list_view ), esc_attr( $list ) ); echo wp_kses_post( apply_filters( 'oceanwp_grid_list_buttons_output', $output ) ); } /** * Closes the opening div "oceanwp-toolbar" around top elements. * * @since 1.1.1 */ public static function close_shop_loop_div() { echo '
'; } /** * Add result count. * * @since 1.1.1 */ public static function result_count() { // Return if is not in shop page if ( ! oceanwp_is_woo_shop() && ! is_product_category() && ! is_product_tag() && ! ocean_is_wc_attribute() ) { return; } get_template_part( 'woocommerce/result-count' ); } /** * Returns correct posts per page for the shop * * @since 1.0.0 */ public static function loop_shop_per_page() { if ( get_theme_mod( 'ocean_woo_shop_result_count', true ) ) { $posts_per_page = ( isset( $_GET['products-per-page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['products-per-page'] ) ) : get_theme_mod( 'ocean_woo_shop_posts_per_page', '12' ); if ( $posts_per_page == 'all' ) { $posts_per_page = wp_count_posts( 'product' )->publish; } } else { $posts_per_page = get_theme_mod( 'ocean_woo_shop_posts_per_page' ); $posts_per_page = $posts_per_page ? $posts_per_page : '12'; } return $posts_per_page; } /** * Change products per row for the main shop. * * @since 1.0.0 */ public static function loop_shop_columns() { $columns = get_theme_mod( 'ocean_woocommerce_shop_columns', '3' ); $columns = $columns ? $columns : '3'; return $columns; } /** * Change products per row for upsells. * * @since 1.0.0 */ public static function upsell_display() { // Get count $count = get_theme_mod( 'ocean_woocommerce_upsells_count', '3' ); $count = $count ? $count : '3'; // Get columns $columns = get_theme_mod( 'ocean_woocommerce_upsells_columns', '3' ); $columns = $columns ? $columns : '3'; // Alter upsell display woocommerce_upsell_display( $count, $columns ); } /** * Change products per row for crossells. * * @since 1.0.0 */ public static function cross_sell_display() { // Get count $count = get_theme_mod( 'ocean_woocommerce_cross_sells_count', '2' ); $count = $count ? $count : '2'; // Get columns $columns = get_theme_mod( 'ocean_woocommerce_cross_sells_columns', '2' ); $columns = $columns ? $columns : '2'; // Alter cross-sell display woocommerce_cross_sell_display( $count, $columns ); } /** * Alter the related product arguments. * * @since 1.0.0 */ public static function related_product_args() { // Get global vars global $product, $orderby, $related; // Get posts per page $posts_per_page = get_theme_mod( 'ocean_woocommerce_related_count', '3' ); $posts_per_page = $posts_per_page ? $posts_per_page : '3'; // Get columns $columns = get_theme_mod( 'ocean_woocommerce_related_columns', '3' ); $columns = $columns ? $columns : '3'; // Return array return array( 'posts_per_page' => $posts_per_page, 'columns' => $columns, ); } /** * Adds an opening div "product-inner" around product entries. * * @since 1.0.0 */ public static function add_shop_loop_item_inner_div() { echo '
'; } /** * Adds an out of stock tag to the products. * * @since 1.0.0 */ public static function add_out_of_stock_badge() { if ( function_exists( 'oceanwp_woo_product_instock' ) && ! oceanwp_woo_product_instock() ) { $label = esc_html__( 'Out of Stock', 'oceanwp' ); ?>
'; } /** * Quick view button. * * @since 1.5.0 */ public static function quick_view_button() { global $product; $button = '' . oceanwp_theme_strings( 'owp-string-woo-quick-view-text', false, 'oceanwp' ) . ''; echo apply_filters( 'ocean_woo_quick_view_button_html', $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Quick view ajax. * * @since 1.5.0 */ public static function product_quick_view_ajax() { if ( ! isset( $_REQUEST['product_id'] ) ) { die(); } $product_id = intval( $_REQUEST['product_id'] ); // wp_query for the product. wp( 'p=' . $product_id . '&post_type=product' ); ob_start(); get_template_part( 'woocommerce/quick-view-content' ); echo ob_get_clean(); die(); } /** * Quick view template. * * @since 1.5.0 */ public static function quick_view_template() { get_template_part( 'woocommerce/quick-view' ); } /** * Quick view image. * * @since 1.5.0 */ public static function quick_view_image() { get_template_part( 'woocommerce/quick-view-image' ); } /** * Clear floats after single product summary. * * @since 1.0.0 */ public static function clear_summary_floats() { echo '
'; } /** * Single product content. * * @since 1.1.9 */ public static function single_product_content() { if ( function_exists( 'wc_get_template' ) ) { wc_get_template( 'owp-single-product.php' ); } } /** * Add product navigation. * * @since 1.5.0 */ public static function product_next_prev_nav() { global $post; $next_post = get_next_post( true, '', 'product_cat' ); $prev_post = get_previous_post( true, '', 'product_cat' ); // Next text $next_text = esc_html__( 'Previous Product', 'oceanwp' ); $next_text = apply_filters( 'ocean_woo_nav_next_text', $next_text ); // Prev text $prev_text = esc_html__( 'Next Product', 'oceanwp' ); $prev_text = apply_filters( 'ocean_woo_nav_prev_text', $prev_text ); ?>

get_title(); ?>

get_price_html(); ?>

get_stock_status() ) { ?>

is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) { echo self::floating_bar_add_to_cart( $product ); } else { ?>
add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">'; $html .= woocommerce_quantity_input( array( 'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: CSRF ok, input var ok. ), $product, false ); $html .= ''; $html .= ''; return $html; } /** * Floating bar add to cart ajax request. * * @since 1.5.0 */ public static function add_cart_floating_bar_ajax() { $product_id = sanitize_text_field( $_POST['product_id'] ); $quantity = sanitize_text_field( $_POST['quantity'] ); WC()->cart->add_to_cart( $product_id, $quantity ); die(); } /** * Add wrap and user info to the account navigation. * * @since 1.0.0 */ public static function oceanwp_before_account_navigation() { // Name to display $current_user = wp_get_current_user(); if ( $current_user->display_name ) { $name = $current_user->display_name; } else { $name = esc_html__( 'Welcome!', 'oceanwp' ); } $name = apply_filters( 'ocean_user_profile_name_text', $name ); echo '
'; echo ''; } /** * Add wrap to the account navigation. * * @since 1.0.0 */ public static function oceanwp_after_account_navigation() { echo '
'; } /** * Adds container wrap for the thumbnail and title of the categories products. * * @since 1.1.1.1 */ public static function add_container_wrap_category() { echo '
'; } /** * Adds a container div before the thumbnail for the categories products. * * @since 1.1.1.1 */ public static function add_div_before_category_thumbnail( $category ) { echo '
'; echo ''; } /** * Close a container div before the thumbnail for the categories products. * * @since 1.1.1.1 */ public static function close_div_after_category_thumbnail() { echo ''; echo '
'; } /** * Adds a container div before the thumbnail for the categories products. * * @since 1.1.1.1 */ public static function add_div_before_category_title( $category ) { echo '
'; echo ''; } /** * Add description if list view for the categories products. * * @since 1.1.1.1 */ public static function add_category_description( $category ) { // Close category link openend in add_div_before_category_title() echo ''; // Var $term = get_term( $category->term_id, 'product_cat' ); $description = $term->description; $length = get_theme_mod( 'ocean_woo_list_excerpt_length', '60' ); // Description if ( get_theme_mod( 'ocean_woo_grid_list', true ) && $description ) { echo '
'; echo '
'; if ( ! $length ) { echo wp_kses_post( strip_shortcodes( $description ) ); } else { echo wp_trim_words( strip_shortcodes( $description ), $length ); } echo '
'; echo '
'; } } /** * Close a container div before the thumbnail for the categories products. * * @since 1.1.1.1 */ public static function close_div_after_category_title() { echo '
'; } /** * Close container wrap for the thumbnail and title of the categories products. * * @since 1.1.1.1 */ public static function close_container_wrap_category() { echo '
'; } /** * Before my account login. * * @since 1.0.0 */ public static function oceanwp_login_wrap_before() { echo '
'; } /** * After my account login. * * @since 1.0.0 */ public static function oceanwp_login_wrap_after() { echo '
'; } /** * Display the categories featured images. * * @since 1.0.0 */ public static function woocommerce_category_image() { if ( is_product_category() ) { global $wp_query; $cat = $wp_query->get_queried_object(); $thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); if ( $image ) { echo '
' . $cat->name . '
'; } } } /** * Tweaks pagination arguments. * * @since 1.0.0 */ public static function pagination_args( $args ) { $args['prev_text'] = ''; $args['next_text'] = ''; return $args; } /** * Alter continue shoping URL. * * @since 1.0.0 */ public static function continue_shopping_redirect( $return_to ) { $shop_id = wc_get_page_id( 'shop' ); if ( function_exists( 'icl_object_id' ) ) { $shop_id = icl_object_id( $shop_id, 'page' ); } if ( $shop_id ) { $return_to = get_permalink( $shop_id ); } return $return_to; } /** * Add classes to WooCommerce product entries. * * @since 1.0.0 */ public static function add_product_classes( $classes ) { global $woocommerce_loop; // Vars $product = wc_get_product( get_the_ID() ); $content_alignment = get_theme_mod( 'ocean_woo_product_entry_content_alignment', 'center' ); $content_alignment = $content_alignment ? $content_alignment : 'center'; $thumbs_layout = get_theme_mod( 'ocean_woo_product_thumbs_layout', 'horizontal' ); $thumbs_layout = $thumbs_layout ? $thumbs_layout : 'horizontal'; $tabs_layout = get_theme_mod( 'ocean_woo_product_tabs_layout', 'horizontal' ); $tabs_layout = $tabs_layout ? $tabs_layout : 'horizontal'; $btn_style = get_theme_mod( 'ocean_woo_product_addtocart_style', 'normal' ); $btn_style = $btn_style ? $btn_style : 'normal'; // Product entries if ( $product && ! empty( $woocommerce_loop['columns'] ) ) { // If has rating if ( $product->get_rating_count() ) { $classes[] = 'has-rating'; } // If product navigation if ( true == get_theme_mod( 'ocean_woocommerce_display_navigation', true ) ) { $classes[] = 'has-product-nav'; } $classes[] = 'col'; $classes[] = oceanwp_grid_class( $woocommerce_loop['columns'] ); $classes[] = 'owp-content-'. $content_alignment; // If infinite scroll if ( 'infinite_scroll' == get_theme_mod( 'ocean_woo_pagination_style', 'standard' ) ) { $classes[] = 'item-entry'; } } // Single product if ( post_type_exists( 'product' ) ) { // Thumbnails layout $classes[] = 'owp-thumbs-layout-' . $thumbs_layout; // Add to cart button style $classes[] = 'owp-btn-' . $btn_style; // Tabs layout $classes[] = 'owp-tabs-layout-' . $tabs_layout; // If no thumbnails $thumbnails = get_post_meta( get_the_ID(), '_product_image_gallery', true ); if ( empty( $thumbnails ) ) { $classes[] = 'has-no-thumbnails'; } } // Sale badge style $sale_style = get_theme_mod( 'ocean_woo_sale_badge_style', 'square' ); if ( 'circle' == $sale_style ) { $classes[] = $sale_style . '-sale'; } return $classes; } /** * Add the product class to the Elementor editor to fix the product display issue. * * @since 1.5.18 */ public static function add_product_class_for_elementor( $classes ) { if ( in_array( 'type-product', $classes ) ) { $classes[] = 'product'; } return $classes; } /** * Remove the category description under the page title on taxonomy. * * @since 1.4.7 */ public static function post_subheading( $return ) { if ( is_woocommerce() && is_product_taxonomy() ) { $return = false; } return $return; } /** * Disables the next/previous links. * * @since 1.0.0 */ public static function next_prev( $return ) { if ( is_woocommerce() && is_singular( 'product' ) ) { $return = false; } return $return; } /** * Adds color accents for WooCommerce styles. * * @since 1.0.0 */ public static function primary_texts( $texts ) { return array_merge( array( '.woocommerce-MyAccount-navigation ul li a:before', '.woocommerce-checkout .woocommerce-info a', '.woocommerce-checkout #payment ul.payment_methods .wc_payment_method>input[type=radio]:first-child:checked+label:before', '.woocommerce-checkout #payment .payment_method_paypal .about_paypal', '.woocommerce ul.products li.product li.category a:hover', '.woocommerce ul.products li.product .button:hover', '.woocommerce ul.products li.product .product-inner .added_to_cart:hover', '.product_meta .posted_in a:hover', '.product_meta .tagged_as a:hover', '.woocommerce div.product .woocommerce-tabs ul.tabs li a:hover', '.woocommerce div.product .woocommerce-tabs ul.tabs li.active a', '.woocommerce .oceanwp-grid-list a.active', '.woocommerce .oceanwp-grid-list a:hover', '.woocommerce .oceanwp-off-canvas-filter:hover', '.widget_shopping_cart ul.cart_list li .owp-grid-wrap .owp-grid a.remove:hover', '.widget_product_categories li a:hover ~ .count', '.widget_layered_nav li a:hover ~ .count', '.woocommerce ul.products li.product:not(.product-category) .woo-entry-buttons li a:hover', ), $texts ); } /** * Adds border accents for WooCommerce styles. * * @since 1.0.0 */ public static function primary_borders( $borders ) { return array_merge( array( '.current-shop-items-dropdown' => array( 'top' ), '.woocommerce div.product .woocommerce-tabs ul.tabs li.active a' => array( 'bottom' ), '.wcmenucart-details.count:before', '.woocommerce ul.products li.product .button:hover', '.woocommerce ul.products li.product .product-inner .added_to_cart:hover', '.woocommerce div.product .woocommerce-tabs ul.tabs li.active a', '.woocommerce .oceanwp-grid-list a.active', '.woocommerce .oceanwp-grid-list a:hover', '.woocommerce .oceanwp-off-canvas-filter:hover', '.owp-product-nav li a.owp-nav-link:hover', '.widget_shopping_cart_content .buttons .button:first-child:hover', '.widget_shopping_cart ul.cart_list li .owp-grid-wrap .owp-grid a.remove:hover', '.widget_product_categories li a:hover ~ .count', '.woocommerce .widget_product_categories li.current-cat > a ~ .count', '.woocommerce .widget_product_categories li.current-cat > a:before', '.widget_layered_nav li a:hover ~ .count', '.woocommerce .widget_layered_nav li.chosen a ~ .count', '.woocommerce .widget_layered_nav li.chosen a:before', '#owp-checkout-timeline.arrow .active .timeline-wrapper:before' => array( 'top', 'bottom' ), '#owp-checkout-timeline.arrow .active .timeline-wrapper:after' => array( 'left', 'right' ), '.bag-style:hover .wcmenucart-cart-icon .wcmenucart-count', '.bag-style:hover .wcmenucart-cart-icon .wcmenucart-count:after', '.show-cart .wcmenucart-cart-icon .wcmenucart-count', '.show-cart .wcmenucart-cart-icon .wcmenucart-count:after', '.woocommerce ul.products li.product:not(.product-category) .woo-product-gallery .active a', '.woocommerce ul.products li.product:not(.product-category) .woo-product-gallery a:hover', ), $borders ); } /** * Adds background accents for WooCommerce styles. * * @since 1.0.0 */ public static function primary_backgrounds( $backgrounds ) { return array_merge( array( '.woocommerce div.product div.images .open-image', '.wcmenucart-details.count', '.woocommerce-message a', '.woocommerce-error a', '.woocommerce-info a', '.woocommerce .widget_price_filter .ui-slider .ui-slider-handle', '.woocommerce .widget_price_filter .ui-slider .ui-slider-range', '.owp-product-nav li a.owp-nav-link:hover', '.woocommerce div.product.owp-tabs-layout-vertical .woocommerce-tabs ul.tabs li a:after', '.woocommerce .widget_product_categories li.current-cat > a ~ .count', '.woocommerce .widget_product_categories li.current-cat > a:before', '.woocommerce .widget_layered_nav li.chosen a ~ .count', '.woocommerce .widget_layered_nav li.chosen a:before', '#owp-checkout-timeline .active .timeline-wrapper', '.bag-style:hover .wcmenucart-cart-icon .wcmenucart-count', '.show-cart .wcmenucart-cart-icon .wcmenucart-count', '.woocommerce ul.products li.product:not(.product-category) .image-wrap .button', ), $backgrounds ); } /** * Adds background hover accents for WooCommerce styles. * * @since 1.0.0 */ public static function hover_primary_backgrounds( $hover ) { return array_merge( array( '.woocommerce div.product div.images .open-image:hover', '.woocommerce-error a:hover', '.woocommerce-info a:hover', '.woocommerce-message a:hover', '.woocommerce ul.products li.product:not(.product-category) .image-wrap .button:hover', ), $hover ); } /** * Adds border color elements for WooCommerce styles. * * @since 1.0.0 */ public static function border_color_elements( $elements ) { return array_merge( array( '.woocommerce table.shop_table', '.woocommerce table.shop_table td', '.woocommerce-cart .cart-collaterals .cart_totals tr td', '.woocommerce-cart .cart-collaterals .cart_totals tr th', '.woocommerce table.shop_table tth', '.woocommerce table.shop_table tfoot td', '.woocommerce table.shop_table tfoot th', '.woocommerce .order_details', '.woocommerce .shop_table.order_details tfoot th', '.woocommerce .shop_table.customer_details th', '.woocommerce .cart-collaterals .cross-sells', '.woocommerce-page .cart-collaterals .cross-sells', '.woocommerce .cart-collaterals .cart_totals', '.woocommerce-page .cart-collaterals .cart_totals', '.woocommerce .cart-collaterals h2', '.woocommerce .cart-collaterals h2', '.woocommerce .cart-collaterals h2', '.woocommerce-cart .cart-collaterals .cart_totals .order-total th', '.woocommerce-cart .cart-collaterals .cart_totals .order-total td', '.woocommerce ul.order_details', '.woocommerce .shop_table.order_details tfoot th', '.woocommerce .shop_table.customer_details th', '.woocommerce .woocommerce-checkout #customer_details h3', '.woocommerce .woocommerce-checkout h3#order_review_heading', '.woocommerce-checkout #payment ul.payment_methods', '.woocommerce-checkout form.login', '.woocommerce-checkout form.checkout_coupon', '.woocommerce-checkout-review-order-table tfoot th', '.woocommerce-checkout #payment', '.woocommerce ul.order_details', '.woocommerce #customer_login > div', '.woocommerce .col-1.address', '.woocommerce .col-2.address', '.woocommerce-checkout .woocommerce-info', '.woocommerce div.product form.cart', '.product_meta', '.woocommerce div.product .woocommerce-tabs ul.tabs', '.woocommerce #reviews #comments ol.commentlist li .comment_container', 'p.stars span a', '.woocommerce ul.product_list_widget li', '.woocommerce .widget_shopping_cart .cart_list li', '.woocommerce.widget_shopping_cart .cart_list li', '.woocommerce ul.product_list_widget li:first-child', '.woocommerce .widget_shopping_cart .cart_list li:first-child', '.woocommerce.widget_shopping_cart .cart_list li:first-child', '.widget_product_categories li a', '.woocommerce .oceanwp-toolbar', '.woocommerce .products.list .product', ), $elements ); } /** * Alter WooCommerce category classes * * @since 1.0.0 */ public static function product_cat_class( $classes ) { global $woocommerce_loop; $classes[] = 'col'; $classes[] = oceanwp_grid_class( $woocommerce_loop['columns'] ); return $classes; } /** * Adds wishlist icon to menu * * @since 1.5.0 */ public static function menu_wishlist_icon( $items, $args ) { // Return items if is in the Elementor edit mode, to avoid error if ( OCEANWP_ELEMENTOR_ACTIVE && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { return $items; } // Return if ( ! class_exists( 'TInvWL_Wishlist' ) || true != get_theme_mod( 'ocean_woo_wishlist_icon', false ) || 'main_menu' != $args->theme_location ) { return $items; } // Add wishlist link to menu items $items .= ''; // Return menu items return $items; } /** * Adds cart icon to menu * * @since 1.0.0 */ public static function menu_cart_icon( $items, $args ) { // Return items if is in the Elementor edit mode, to avoid error if ( OCEANWP_ELEMENTOR_ACTIVE && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { return $items; } // Only used for the main menu if ( 'main_menu' != $args->theme_location ) { return $items; } // Get style $style = oceanwp_menu_cart_style(); $header_style = oceanwp_header_style(); // Return items if no style if ( ! $style ) { return $items; } // Add cart link to menu items if ( 'full_screen' == $header_style ) { $items .= ''; } else { $items .= self::get_cart_icon(); } // Return menu items return $items; } /** * Add cart icon * * @since 1.5.0 */ public static function get_cart_icon() { // Style $style = oceanwp_menu_cart_style(); $header_style = oceanwp_header_style(); $cart_style = get_theme_mod( 'ocean_woo_cart_dropdown_style', 'compact' ); // Toggle class $toggle_class = 'toggle-cart-widget'; // Define classes to add to li element $classes = array( 'woo-menu-icon' ); // Add style class $classes[] = 'wcmenucart-toggle-'. $style; // If bag style if ( 'yes' == get_theme_mod( 'ocean_woo_menu_bag_style', 'no' ) ) { $classes[] = 'bag-style'; } // Cart style if ( 'compact' != $cart_style ) { $classes[] = $cart_style; } // Prevent clicking on cart and checkout if ( 'custom_link' != $style && ( is_cart() || is_checkout() ) ) { $classes[] = 'nav-no-click'; } // Add toggle class else { $classes[] = $toggle_class; } // Turn classes into string $classes = implode( ' ', $classes ); ob_start(); ?>
  • is_type( 'simple' ) || $product->is_type( 'external' ) ) { $r_price = $product->get_regular_price(); $s_price = $product->get_sale_price(); $percent = round( ( ( floatval( $r_price ) - floatval( $s_price ) ) / floatval( $r_price ) ) * 100 ); } else if ( $product->is_type( 'variable' ) ) { $available_variations = $product->get_available_variations(); $maximumper = 0; for ( $i = 0; $i < count( $available_variations ); ++ $i ) { $variation_id = $available_variations[ $i ]['variation_id']; $variable_product = new WC_Product_Variation( $variation_id ); if ( ! $variable_product->is_on_sale() ) { continue; } $r_price = $variable_product->get_regular_price(); $s_price = $variable_product->get_sale_price(); $percent = round( ( ( floatval( $r_price ) - floatval( $s_price ) ) / floatval( $r_price ) ) * 100 ); if ( $percent > $maximumper ) { $maximumper = $percent; } } $percent = sprintf( __( '%s', 'oceanwp' ), $maximumper ); } else { $percent = '' . __( 'Sale!', 'oceanwp' ) . ''; return $percent; } $value = '-' . esc_html( $percent ) . '%'; return '' . esc_html( $value ) . ''; } /** * Add links Login/Register on the my account page * * @since 1.5.0 */ public static function login_register_links() { // Return if not Original style if ( 'original' != get_theme_mod( 'ocean_woo_account_page_style', 'original' ) ) { return; } // Var $registration = get_option( 'woocommerce_enable_myaccount_registration' ); // Define classes $classes = array( 'owp-account-links' ); // If registration disabled if ( 'yes' != $registration ) { $classes[] = 'registration-disabled'; } // Turn classes into string $classes = implode( ' ', $classes ); // Login text $text = esc_html__( 'Login', 'oceanwp' ); $html = ''; echo $html; } /** * Distraction free on cart/checkout * * @since 1.5.0 */ public static function distraction_free( $return ) { if ( ( is_cart() && true == get_theme_mod( 'ocean_woo_distraction_free_cart', false ) ) || ( is_checkout() && true == get_theme_mod( 'ocean_woo_distraction_free_checkout', false ) ) ) { $return = false; } // Return return $return; } /** * Validate multi-step checkout fields. * * @since 1.5.17 */ public function validate_checkout_callback() { $posted_data = isset($_POST['posted_data'])?$_POST['posted_data']:array(); $WC_Checkout = new WC_Checkout(); $errors = new WP_Error(); //////////////////////////////////////// $skipped = array(); $data = array( 'terms' => (int) isset($posted_data['terms']), 'createaccount' => (int) !empty($posted_data['createaccount']), 'payment_method' => isset($posted_data['payment_method']) ? wc_clean($posted_data['payment_method']) : '', 'shipping_method' => isset($posted_data['shipping_method']) ? wc_clean($posted_data['shipping_method']) : '', 'ship_to_different_address' => !empty($posted_data['ship_to_different_address']) && !wc_ship_to_billing_address_only(), 'woocommerce_checkout_update_totals' => isset($posted_data['woocommerce_checkout_update_totals']), ); foreach ($WC_Checkout->get_checkout_fields() as $fieldset_key => $fieldset) { if (isset($data['ship_to_different_address'])) { if ('shipping' === $fieldset_key && (!$data['ship_to_different_address'] || !WC()->cart->needs_shipping_address() )) { continue; } } if (isset($data['createaccount'])) { if ('account' === $fieldset_key && ( is_user_logged_in() || (!$WC_Checkout->is_registration_required() && empty($data['createaccount']) ) )) { continue; } } foreach ($fieldset as $key => $field) { $type = sanitize_title(isset($field['type']) ? $field['type'] : 'text' ); switch ($type) { case 'checkbox' : $value = isset($posted_data[$key]) ? 1 : ''; break; case 'multiselect' : $value = isset($posted_data[$key]) ? implode(', ', wc_clean($posted_data[$key])) : ''; break; case 'textarea' : $value = isset($posted_data[$key]) ? wc_sanitize_textarea($posted_data[$key]) : ''; break; default : $value = isset($posted_data[$key]) ? wc_clean($posted_data[$key]) : ''; break; } $data[$key] = apply_filters('woocommerce_process_checkout_' . $type . '_field', apply_filters('woocommerce_process_checkout_field_' . $key, $value)); } } if (in_array('shipping', $skipped) && ( WC()->cart->needs_shipping_address() || wc_ship_to_billing_address_only() )) { foreach ($this->get_checkout_fields('shipping') as $key => $field) { $data[$key] = isset($data['billing_' . substr($key, 9)]) ? $data['billing_' . substr($key, 9)] : ''; } } ////////////////////////////////////////////////// foreach ($WC_Checkout->get_checkout_fields() as $fieldset_key => $fieldset) { if($fieldset_key!=$_POST['type']) continue; if (isset($data['ship_to_different_address'])) { if ('shipping' === $fieldset_key && (!$data['ship_to_different_address'] || !WC()->cart->needs_shipping_address() )) { continue; } } if (isset($data['createaccount'])) { if ('account' === $fieldset_key && ( is_user_logged_in() || (!$WC_Checkout->is_registration_required() && empty($data['createaccount']) ) )) { continue; } } foreach ($fieldset as $key => $field) { if (!isset($data[$key])) { continue; } $required = !empty($field['required']); $format = array_filter(isset($field['validate']) ? (array) $field['validate'] : array() ); $field_label = isset($field['label']) ? $field['label'] : ''; switch ($fieldset_key) { case 'shipping' : /* translators: %s: field name */ $field_label = sprintf(__('Shipping %s', 'oceanwp'), $field_label); break; case 'billing' : /* translators: %s: field name */ $field_label = sprintf(__('Billing %s', 'oceanwp'), $field_label); break; } if (in_array('postcode', $format)) { $country = isset($data[$fieldset_key . '_country']) ? $data[$fieldset_key . '_country'] : WC()->customer->{"get_{$fieldset_key}_country"}(); $data[$key] = wc_format_postcode($data[$key], $country); if ('' !== $data[$key] && !WC_Validation::is_postcode($data[$key], $country)) { $errors->add('validation', sprintf(__('%s is not a valid postcode / ZIP.', 'oceanwp'), '' . esc_html($field_label) . '')); } } if (in_array('phone', $format)) { $data[$key] = wc_format_phone_number($data[$key]); if ('' !== $data[$key] && !WC_Validation::is_phone($data[$key])) { /* translators: %s: phone number */ $errors->add('validation', sprintf(__('%s is not a valid phone number.', 'oceanwp'), '' . esc_html($field_label) . '')); } } if (in_array('email', $format) && '' !== $data[$key]) { $data[$key] = sanitize_email($data[$key]); if (!is_email($data[$key])) { /* translators: %s: email address */ $errors->add('validation', sprintf(__('%s is not a valid email address.', 'oceanwp'), '' . esc_html($field_label) . '')); continue; } } if ('' !== $data[$key] && in_array('state', $format)) { $country = isset($data[$fieldset_key . '_country']) ? $data[$fieldset_key . '_country'] : WC()->customer->{"get_{$fieldset_key}_country"}(); $valid_states = WC()->countries->get_states($country); if (!empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { $valid_state_values = array_map('wc_strtoupper', array_flip(array_map('wc_strtoupper', $valid_states))); $data[$key] = wc_strtoupper($data[$key]); if (isset($valid_state_values[$data[$key]])) { // With this part we consider state value to be valid as well, convert it to the state key for the valid_states check below. $data[$key] = $valid_state_values[$data[$key]]; } if (!in_array($data[$key], $valid_state_values)) { /* translators: 1: state field 2: valid states */ $errors->add('validation', sprintf(__('%1$s is not valid. Please enter one of the following: %2$s', 'oceanwp'), '' . esc_html($field_label) . '', implode(', ', $valid_states))); } } } if ($required && '' === $data[$key]) { /* translators: %s: field name */ $errors->add('required-field', apply_filters('woocommerce_checkout_required_field_notice', sprintf(__('%s is a required field.', 'oceanwp'), '' . esc_html($field_label) . ''), $field_label)); } } } $html = ''; $valid = TRUE; if ($errors->get_error_messages()) { $valid = FALSE; $html = '
    '; } wp_send_json(array("valid"=>$valid,"html"=>$html)); wp_die(); } /** * Checkout timeline template. * * @since 1.5.0 */ public static function checkout_timeline() { get_template_part( 'woocommerce/checkout/checkout-timeline' ); } /** * Change checkout template * * @since 1.5.0 */ public function multistep_checkout( $template, $template_name, $template_path ) { if ( 'checkout/form-checkout.php' == $template_name ) { $template = OCEANWP_THEME_DIR . '/woocommerce/checkout/form-multistep-checkout.php'; $theme_file = get_stylesheet_directory() . '/woocommerce/checkout/form-multistep-checkout.php'; if ( file_exists( $theme_file ) ) { $template = $theme_file; } } // Return return $template; } /** * Checkout login form. * * @since 1.5.0 */ public static function checkout_login_form( $login_message ) { woocommerce_login_form( array( 'message' => $login_message, 'redirect' => wc_get_page_permalink( 'checkout' ), 'hidden' => false ) ); // If WooCommerce social login if ( class_exists( 'WC_Social_Login' ) ) { do_shortcode( '[woocommerce_social_login_buttons]' ); } } /** * Support to WooCommerce secure submit gateway * * @since 1.5.0 */ public static function woocommerce_securesubmit_support( $value, $options ) { $value['use_iframes'] = 'no'; return $value; } /** * Add typography options for the WooCommerce product title * * @since 1.0.0 */ public static function typography_settings( $settings ) { $settings['woo_product_title'] = array( 'label' => esc_html__( 'WooCommerce Product Title', 'oceanwp' ), 'target' => '.woocommerce div.product .product_title', 'defaults' => array( 'font-size' => '24', 'color' => '#333333', 'line-height' => '1.4', 'letter-spacing' => '0.6', ), ); $settings['woo_product_price'] = array( 'label' => esc_html__( 'WooCommerce Product Price', 'oceanwp' ), 'target' => '.woocommerce div.product p.price', 'defaults' => array( 'font-size' => '36', 'line-height' => '1', 'letter-spacing' => '0', ), ); $settings['woo_product_add_to_cart'] = array( 'label' => esc_html__( 'WooCommerce Product Add To Cart', 'oceanwp' ), 'target' => '.woocommerce ul.products li.product .button, .woocommerce ul.products li.product .product-inner .added_to_cart', 'exclude' => array( 'font-color' ), 'defaults' => array( 'font-size' => '12', 'line-height' => '1.5', 'letter-spacing' => '1', ), ); return $settings; } /** * Supports WooCommerce Match Box extension by removing * duplicate single product summary features on the * product page. * * @since 1.2.9 * @static * @author Sébastien Dumont * @global object WC_Product $product */ public function remove_wc_match_box_single_product_summary() { global $product; if ( $product->is_type( 'mix-and-match' ) ) { remove_action( 'woocommerce_single_product_summary', array( $this, 'single_product_content' ), 10 ); add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); } } /** * Compatibility with YITH WooCommerce Badge. * * @since 1.5.23 */ public function yith_wcbm_shop_badge_container_start() { do_action( 'yith_wcbm_theme_badge_container_start' ); } /** * Compatibility with YITH WooCommerce Badge. * * @since 1.5.23 */ public function yith_wcbm_shop_badge_container_end() { do_action( 'yith_wcbm_theme_badge_container_end' ); } /** * Compatibility with WooCommerce Germanized. * * @since 1.5.6 */ public function woocommerce_germanized() { echo '
  • '; wc_get_template( 'single-product/tax-info.php' ); wc_get_template( 'single-product/shipping-costs-info.php' ); echo '
  • '; } } } new OceanWP_WooCommerce_Config();