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' => '';
}
/**
* 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_icon( 'eye', false ) . ' ' . oceanwp_theme_strings( 'owp-string-woo-quick-view-text', false ) . ' ';
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( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'oceanwp' ) ) {
wp_die();
}
if ( ! isset( $_POST['product_id'] ) ) {
wp_die();
}
$product_id = intval( $_POST['product_id'] );
// wp_query for the product.
wp( 'p=' . $product_id . '&post_type=product' );
ob_start();
get_template_part( 'woocommerce/quick-view-content' );
$output = ob_get_clean();
echo wp_json_encode( array( 'output' => $output ) );
wp_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' );
$ocean_next_prev_prod_content = '';
if ( is_a( $prev_post, 'WP_Post' ) ) {
$next_arrow = is_rtl() ? oceanwp_icon( 'angle_right', false ) : oceanwp_icon( 'angle_left', false );
ob_start();
?>
< class="entry-title" itemprop="name">get_title(), '4' ); ?>>
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 .= '
' . esc_html( $product->add_to_cart_text() ) . ' ';
$html .= '';
return $html;
}
/**
* Floating bar add to cart ajax request.
*
* @since 1.5.0
*/
public static function add_cart_floating_bar_ajax() {
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'oceanwp' ) ) {
wp_die();
}
$product_id = sanitize_text_field( $_POST['product_id'] );
$quantity = sanitize_text_field( $_POST['quantity'] );
$cart_item_key = WC()->cart->add_to_cart( $product_id, $quantity );
echo $cart_item_key;
wp_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 '
';
echo '
' . get_avatar( $current_user->user_email, 128 ) . '
';
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 '
';
}
/**
* 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 '
';
}
}
}
/**
* Tweaks pagination arguments.
*
* @since 1.0.0
*/
public static function pagination_args( $args ) {
// Nav icons.
$p_arrow = is_rtl() ? oceanwp_icon( 'angle_right', false ) : oceanwp_icon( 'angle_left', false );
$n_arrow = is_rtl() ? oceanwp_icon( 'angle_left', false ) : oceanwp_icon( 'angle_right', false );
// Args.
$args['prev_text'] = $p_arrow;
$args['next_text'] = $n_arrow;
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';
}
// Column Alignment.
$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';
}
// Display product navigation.
if ( true == get_theme_mod( 'ocean_woocommerce_display_navigation', true ) ) {
$classes[] = 'has-product-nav';
}
}
// 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;
}
/**
* Disable woo css
*
* @since 1.4.7
*/
public function disable_woo_css() {
$styles = [];
return $styles;
}
/**
* 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 color accents for SVG icons.
*
* @since 1.0.0
*/
public static function primary_svg_icons( $svg_icons ) {
return array_merge(
array(
'.woocommerce .oceanwp-grid-list a.active .owp-icon use',
'.woocommerce .oceanwp-grid-list a:hover .owp-icon use',
),
$svg_icons
);
}
/**
* 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-message a:focus',
'.woocommerce .button:focus',
'.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 ( ! ocean_woo_wishlist()
|| true != get_theme_mod( 'ocean_woo_wishlist_icon', false )
|| 'main_menu' != $args->theme_location ) {
return $items;
}
$wl_plugin = get_theme_mod( 'ocean_woo_wl_plugin', 'ti_wl' );
$items .= '
';
if ( 'ti_wl' === $wl_plugin ) {
$items .= do_shortcode( '[ti_wishlist_products_counter]' );
} elseif ( 'yith_wl' === $wl_plugin ) {
// Get YITH Wishlist URL.
$wishlist_url = YITH_WCWL()->get_last_operation_url();
$woo_wl_count = ocean_woo_wishlist_count();
$items .= '' . oceanwp_icon( 'heart', false ) . '' . esc_html( $woo_wl_count ) . ' ';
}
$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 .= '
' . esc_html__( 'Your cart', 'oceanwp' ) . ' ';
} 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 );
} elseif ( $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 = '
';
$html .= '';
if ( 'yes' == $registration ) {
$html .= '' . $text . ' ';
} else {
$html .= '' . $text . ' ';
}
$html .= ' ';
// If registration
if ( 'yes' == $registration ) {
$html .= '' . esc_html__( 'Or', 'oceanwp' ) . ' ';
$html .= '';
$html .= '' . esc_html__( 'Register', 'oceanwp' ) . ' ';
$html .= ' ';
}
$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 = '
';
foreach ( $errors->get_error_messages() as $message ) {
$html .= '' . $message . ' ';
}
$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_single_add_to_cart'] = array(
'label' => esc_html__( 'WooCommerce Product Add To Cart', 'oceanwp' ),
'target' => '.woocommerce .owp-btn-normal .summary form button.button, .woocommerce .owp-btn-big .summary form button.button, .woocommerce .owp-btn-very-big .summary form button.button',
'exclude' => array( 'font-color' ),
'defaults' => array(
'font-size' => '12',
'text-transform' => 'uppercase',
'line-height' => '1.5',
'letter-spacing' => '1',
),
);
$settings['woo_single_notice'] = array(
'label' => esc_html__( 'WooCommerce Product Notice', 'oceanwp' ),
'target' => '.woocommerce div.owp-woo-single-cond-notice span, .woocommerce div.owp-woo-single-cond-notice a',
'exclude' => array( 'font-color' ),
'defaults' => array(
'font-size' => '18',
'font-weight' => '600',
'text-transform' => 'capitalize',
'line-height' => '2',
'letter-spacing' => '1.5',
),
);
$settings['woo_archive_title'] = array(
'label' => esc_html__( 'WooCommerce Archive Title', 'oceanwp' ),
'target' => '.woocommerce ul.products li.product li.title h2, .woocommerce ul.products li.product li.title a',
'exclude' => array( 'font-color' ),
'defaults' => array(
'font-size' => '14',
'line-height' => '1.5',
'letter-spacing' => '0',
),
);
$settings['woo_archive_cats'] = array(
'label' => esc_html__( 'WooCommerce Archive Category', 'oceanwp' ),
'target' => '.woocommerce ul.products li.product li.category, .woocommerce ul.products li.product li.category a',
'exclude' => array( 'font-color' ),
'defaults' => array(
'font-size' => '12',
'line-height' => '1',
'letter-spacing' => '0',
),
);
$settings['woo_archive_price'] = array(
'label' => esc_html__( 'WooCommerce Archive Price', 'oceanwp' ),
'target' => '.woocommerce ul.products li.product .price',
'exclude' => array( 'font-color' ),
'defaults' => array(
'font-size' => '18',
'line-height' => '1',
'letter-spacing' => '0',
),
);
$settings['woo_product_add_to_cart'] = array(
'label' => esc_html__( 'WooCommerce Archive 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',
),
);
$settings['woo_archive_notice'] = array(
'label' => esc_html__( 'WooCommerce Archive Notice', 'oceanwp' ),
'target' => '.woocommerce ul.products li.owp-woo-cond-notice span, .woocommerce ul.products li.owp-woo-cond-notice a',
'exclude' => array( 'font-color' ),
'defaults' => array(
'font-size' => '16',
'font-weight' => '600',
'text-transform' => 'capitalize',
'line-height' => '1',
'letter-spacing' => '1',
),
);
$settings['woo_store_notice'] = array(
'label' => esc_html__( 'WooCommerce Store Notice', 'oceanwp' ),
'target' => '.woocommerce-store-notice.demo_store',
'defaults' => array(
'color' => '#ffffff',
'line-height' => '2',
'letter-spacing' => '1.5',
),
);
$settings['woo_store_notice_dismiss_link'] = array(
'label' => esc_html__( 'WooCommerce Store Notice Dismiss', 'oceanwp' ),
'target' => '.demo_store .woocommerce-store-notice__dismiss-link',
'defaults' => array(
'color' => '#ffffff',
'line-height' => '2',
'letter-spacing' => '1.5',
),
);
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 '
';
foreach ( wc_gzd_get_product_loop_shopmarks() as $shopmark ) {
$callback = $shopmark->get_callback();
if ( function_exists( $callback ) && $shopmark->is_enabled() && in_array( $shopmark->get_type(), array( 'unit_price', 'tax', 'shipping_costs', 'delivery_time', 'units' ), true ) ) {
call_user_func( $callback );
}
}
echo ' ';
}
public function woocommerce_germanized_single() {
echo '
';
foreach ( wc_gzd_get_single_product_shopmarks() as $shopmark ) {
$callback = $shopmark->get_callback();
if ( function_exists( $callback ) && $shopmark->is_enabled() && in_array( $shopmark->get_type(), array( 'unit_price', 'legal', 'shipping_costs' ), true ) ) {
call_user_func( $callback );
}
}
echo '
';
}
/**
* Compatibility with WooCommerce Germanized Single Product meta template.
*
* @since 2.0
*/
public function woocommerce_germanized_single_meta() {
echo '
';
foreach ( wc_gzd_get_single_product_shopmarks() as $shopmark ) {
$callback = $shopmark->get_callback();
if ( function_exists( $callback ) && $shopmark->is_enabled() && in_array( $shopmark->get_type(), array( 'unit_price', 'delivery_time' ), true ) ) {
call_user_func( $callback );
}
}
echo '
';
}
}
}
new OceanWP_WooCommerce_Config();