芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/wp-content/themes/dexolix/inc/woocommerce.php
300, 'single_image_width' => 600, 'product_grid' => array( 'default_rows' => 3, 'min_rows' => 1, 'default_columns' => 4, 'min_columns' => 1, 'max_columns' => 6, ), ) ); add_theme_support('wc-product-gallery-zoom'); add_theme_support('wc-product-gallery-lightbox'); add_theme_support('wc-product-gallery-slider'); add_filter('woocommerce_enqueue_styles', '__return_false'); } add_action('after_setup_theme', 'dexolix_woocommerce_setup'); /** * WooCommerce specific scripts & stylesheets. * * @return void */ function dexolix_woocommerce_scripts() { wp_enqueue_style('dexolix-woocommerce-style', get_template_directory_uri() . '/woocommerce.css', array(), _S_VERSION); $font_path = WC()->plugin_url() . '/assets/fonts/'; $inline_font = '@font-face { font-family: "star"; src: url("' . $font_path . 'star.eot"); src: url("' . $font_path . 'star.eot?#iefix") format("embedded-opentype"), url("' . $font_path . 'star.woff") format("woff"), url("' . $font_path . 'star.ttf") format("truetype"), url("' . $font_path . 'star.svg#star") format("svg"); font-weight: normal; font-style: normal; }'; wp_add_inline_style('dexolix-woocommerce-style', $inline_font); } add_action('wp_enqueue_scripts', 'dexolix_woocommerce_scripts'); /** * Disable the default WooCommerce stylesheet. * * Removing the default WooCommerce stylesheet and enqueing your own will * protect you during WooCommerce core updates. * * @link https://docs.woocommerce.com/document/disable-the-default-stylesheet/ */ add_filter('woocommerce_enqueue_styles', '__return_empty_array'); /** * Add 'woocommerce-active' class to the body tag. * * @param array $classes CSS classes applied to the body tag. * * @return array $classes modified to include 'woocommerce-active' class. */ function dexolix_woocommerce_active_body_class($classes) { $classes[] = 'woocommerce-active'; return $classes; } add_filter('body_class', 'dexolix_woocommerce_active_body_class'); /** * Related Products Args. * * @param array $args related products args. * * @return array $args related products args. */ function dexolix_woocommerce_related_products_args($args) { $defaults = array( 'posts_per_page' => 3, 'columns' => 3, ); $args = wp_parse_args($defaults, $args); return $args; } add_filter('woocommerce_output_related_products_args', 'dexolix_woocommerce_related_products_args'); /** * Remove default WooCommerce wrapper. */ remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); if (!function_exists('dexolix_woocommerce_wrapper_before')) { /** * Before Content. * * Wraps all WooCommerce content in wrappers which match the theme markup. * * @return void */ function dexolix_woocommerce_wrapper_before() { $breadcrumb_switch = cs_get_option('breadcrumb_switch') ?? ""; ?>
*/ if (!function_exists('dexolix_woocommerce_cart_link_fragment')) { /** * Cart Fragments. * * Ensure cart contents update when products are added to the cart via AJAX. * * @param array $fragments Fragments to refresh via AJAX. * * @return array Fragments to refresh via AJAX. */ function dexolix_woocommerce_cart_link_fragment($fragments) { ob_start(); dexolix_woocommerce_cart_link(); $fragments['a.cart-contents'] = ob_get_clean(); return $fragments; } } add_filter('woocommerce_add_to_cart_fragments', 'dexolix_woocommerce_cart_link_fragment'); if (!function_exists('dexolix_woocommerce_cart_link')) { /** * Cart Link. * * Displayed a link to the cart including the number of items present and the cart total. * * @return void */ function dexolix_woocommerce_cart_link() { ?>
cart->get_cart_contents_count(), 'dexolix'), WC()->cart->get_cart_contents_count() ); ?>
cart->get_cart_subtotal()); ?>
'', ); the_widget('WC_Widget_Cart', $instance); ?>
Parent Theme > Custom Folder > WooCommerce Default */ function dexolix_wc_locate_template($template, $template_name, $template_path) { if (!$template_path) { $template_path = 'woocommerce/'; } // Paths to check $paths_to_check = [ get_stylesheet_directory() . '/' . $template_path . $template_name, // Child Theme get_template_directory() . '/' . $template_path . $template_name, // Parent Theme DEXOLIX_PATH . '/inc/vendor/woocommerce/' . $template_name, // Custom Folder ]; foreach ($paths_to_check as $path) { if (file_exists($path)) { return $path; } } // Fallback to the original WooCommerce template return $template; } add_filter('woocommerce_locate_template', 'dexolix_wc_locate_template', 10, 3); /** * Override WooCommerce template parts. */ function dexolix_override_woocommerce_template_parts($template, $slug, $name) { $template_path = 'woocommerce/'; $filename = $name ? "{$slug}-{$name}.php" : "{$slug}.php"; // Paths to check $paths_to_check = [ get_stylesheet_directory() . '/' . $template_path . $filename, // Child Theme get_template_directory() . '/' . $template_path . $filename, // Parent Theme DEXOLIX_PATH . '/inc/vendor/woocommerce/' . $filename, // Custom Folder ]; foreach ($paths_to_check as $path) { if (file_exists($path)) { return $path; } } // Fallback to the original WooCommerce template part return $template; } add_filter('wc_get_template_part', 'dexolix_override_woocommerce_template_parts', 10, 3); /** * Override main WooCommerce templates (e.g., archive-product, single-product). */ function dexolix_woocommerce_template_include($template) { if (is_singular('product')) { $custom_template = get_stylesheet_directory() . '/woocommerce/single-product.php'; if (file_exists($custom_template)) { return $custom_template; // Child Theme } $custom_template = get_template_directory() . '/woocommerce/single-product.php'; if (file_exists($custom_template)) { return $custom_template; // Parent Theme } $custom_template = DEXOLIX_PATH . '/inc/vendor/woocommerce/single-product.php'; if (file_exists($custom_template)) { return $custom_template; // Custom Folder } } elseif (is_post_type_archive('product') || is_tax('product_cat') || is_tax('product_tag')) { $custom_template = get_stylesheet_directory() . '/woocommerce/archive-product.php'; if (file_exists($custom_template)) { return $custom_template; // Child Theme } $custom_template = get_template_directory() . '/woocommerce/archive-product.php'; if (file_exists($custom_template)) { return $custom_template; // Parent Theme } $custom_template = DEXOLIX_PATH . '/inc/vendor/woocommerce/archive-product.php'; if (file_exists($custom_template)) { return $custom_template; // Custom Folder } } return $template; } add_filter('template_include', 'dexolix_woocommerce_template_include', 99); /** * Customize WooCommerce Single Product Gallery Thumbnail Size. */ function dexolix_custom_woocommerce_gallery_thumbnail_size($size): array { // Set your desired width and height in pixels. $size = array( 'width' => 150, // Change this to your desired width. 'height' => 150, // Change this to your desired height. 'crop' => 1, // 1 means cropping is enabled; 0 disables cropping. ); return $size; } add_filter('woocommerce_get_image_size_gallery_thumbnail', 'dexolix_custom_woocommerce_gallery_thumbnail_size'); add_filter('woocommerce_add_to_cart_fragments', 'dexolix_refresh_mini_cart_count'); function dexolix_refresh_mini_cart_count($fragments) { ob_start(); ?>
cart->get_cart_contents_count(); ?>
cart->get_cart_contents_count(); ?>
cart->get_cart_contents_count(), 'dexolix'), WC()->cart->get_cart_contents_count() ); ?>
cart->get_cart_subtotal()); ?>
'', ); the_widget('WC_Widget_Cart', $instance); ?>
is_in_stock(); if ($out_of_stock) { ?>
get_gallery_image_ids(); $class = 'show-on-hover hide-for-small dexolix-back-image'; if ($attachment_ids) { $loop = 0; foreach ($attachment_ids as $attachment_id) { $image_link = wp_get_attachment_url($attachment_id); if (!$image_link) { continue; } $loop++; echo apply_filters('dexolix_woocommerce_get_alt_product_thumbnail', wp_get_attachment_image($attachment_id, 'woocommerce_thumbnail', false, array('class' => $class))); if ($loop == 1) { break; } } } } } add_action('dexolix_woocommerce_shop_loop_images', 'dexolix_woocommerce_get_alt_product_thumbnail', 11); add_action('dexolix_woocommerce_shop_loop_images', 'dexolix_woo_thumbnail', 11); /* Remove and add Product image */ //remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action('dexolix_woocommerce_shop_loop_images', 'woocommerce_template_loop_product_thumbnail', 10); if (class_exists('WPCleverWoosc')) { add_filter('woosc_button_position_archive', '__return_false'); add_filter('woosc_button_position_single', '__return_false'); } //============================================================================== // Add Wishlist Icon in Product Card //============================================================================== function dexolix_wishlist_icon_with_tooltip_in_product_grid(): void { if (class_exists('YITH_WCWL')) : global $product; ?>
is_product_in_wishlist($product->get_id()) ? esc_attr(get_option('yith_wcwl_browse_wishlist_text')) : esc_attr(get_option('yith_wcwl_add_to_wishlist_text')); ?>
is_product_in_wishlist($product->get_id()) ? esc_attr(get_option('yith_wcwl_browse_wishlist_text')) : esc_attr(get_option('yith_wcwl_add_to_wishlist_text')); ?>
is_product_in_wishlist($post->ID)) { $status = 'remove-item'; } ?>
'; } else { echo '
'; } ?>
get_id(); if (!isset($button_text) || $button_text == 'default') { $button_text = get_option('yith_woocompare_button_text', __('Compare', 'dexolix')); do_action('wpml_register_single_string', 'Plugins', 'plugin_yit_compare_button_text', $button_text); $button_text = apply_filters('wpml_translate_single_string', $button_text, 'Plugins', 'plugin_yit_compare_button_text'); } ?>
get_id(); $comparetxt = cs_get_option('dexolix_compare_text'); ?>
get_id(); if (!isset($button_text) || $button_text == 'default') { $button_text = get_option('yith_woocompare_button_text', __('Compare', 'dexolix')); do_action('wpml_register_single_string', 'Plugins', 'plugin_yit_compare_button_text', $button_text); $button_text = apply_filters('wpml_translate_single_string', $button_text, 'Plugins', 'plugin_yit_compare_button_text'); } ?>
get_id(); $comparetxt = cs_get_option('dexolix_compare_text'); ?>
get_id(); $args = ""; ?>
%s
', esc_url($product->add_to_cart_url()), esc_attr(isset($args['quantity']) ? $args['quantity'] : 1), esc_attr(isset($args['class']) ? $args['class'] : 'button'), isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '', esc_html($product->add_to_cart_text()) ), $product, $args); ?> get_id(); $args = ""; ?>
Add To Cart
%s
', esc_url($product->add_to_cart_url()), esc_attr(isset($args['quantity']) ? $args['quantity'] : 1), esc_attr(isset($args['class']) ? $args['class'] : 'button'), isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '', esc_html($product->add_to_cart_text()) ), $product, $args); ?>
ID . '&nonce=' . $nonce); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail', true); if ($image) { $image = $image[0]; } if ($product->is_type('external')) { $product_url = $product->add_to_cart_url(); $button_text = $product->single_add_to_cart_text(); ?>
is_type('variable')) { ?>
get_stock_status() == 'outofstock') || ($product->get_stock_quantity() && $product->get_stock_quantity() == 0)) { ?>
ID . '&nonce=' . $nonce); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail', true); if ($image) { $image = $image[0]; } if ($product->is_type('external')) { $product_url = $product->add_to_cart_url(); $button_text = $product->single_add_to_cart_text(); ?>
is_type('variable')) { $button_text = $product->single_add_to_cart_text(); ?>
get_stock_status() == 'outofstock') || ($product->get_stock_quantity() && $product->get_stock_quantity() == 0)) { $button_text = $product->single_add_to_cart_text(); ?>
single_add_to_cart_text(); ?>
cart->add_to_cart($_REQUEST['id']); } echo 'OK'; wp_die(); } add_action('wp_ajax_dexolix_close_banner', 'dexolix_close_banner'); add_action('wp_ajax_nopriv_dexolix_close_banner', 'dexolix_close_banner'); function dexolix_close_banner() { // if ( !wp_verify_nonce( $_REQUEST['nonce'], "close_banner")) { // exit("Verification error, please try again!"); // } setcookie('dexolix_close_banner', dexolix_get_option('banner-id'), time() * 40, '/'); wp_die(); } function dexolix_show_banner() { $id = dexolix_get_option('banner-id'); if (isset($_COOKIE['dexolix_close_banner'])) { if ($_COOKIE['dexolix_close_banner'] == $id) { return false; } } return true; } //============================================================================== // Remove WooCommerce product and WordPress page results from the search form widget //============================================================================== function dexolix_modify_search_result($query) { // Make sure this isn't the admin or is the main query if (is_admin() || !$query->is_main_query()) { return; } // Make sure this isn't the WooCommerce product search form if (isset($_GET['post_type']) && ($_GET['post_type'] == 'product')) { return; } if ($query->is_search()) { $in_search_post_types = get_post_types(array('exclude_from_search' => false)); // The post types you're removing (example: 'product' and 'page') $post_types_to_remove = array('product'); foreach ($post_types_to_remove as $post_type_to_remove) { if (is_array($in_search_post_types) && in_array($post_type_to_remove, $in_search_post_types)) { unset($in_search_post_types[$post_type_to_remove]); $query->set('post_type', $in_search_post_types); } } } } add_action('pre_get_posts', 'dexolix_modify_search_result'); //============================================================================== // Product Review Widgets //============================================================================== //add_action('woocommerce_after_shop_loop_item', 'dexolix_get_star_rating'); function dexolix_get_star_rating() { global $woocommerce, $product; $average = $product->get_average_rating(); if (!$average) { echo '
'; } else { echo wc_get_rating_html($average); } } //============================================================================== // Dokan Widgets //============================================================================== add_action('dexolix_seller_information_main', 'dexolix_sold_by'); function dexolix_sold_by() { ?> get_id()); $author = get_user_by('id', $seller); $store_info = dokan_get_store_info($author->ID); if (!empty($store_info['store_name'])) { ?>
%s', dokan_get_store_url($author->ID), $author->display_name); ?>
get_id()); $author = get_user_by('id', $seller); $store_info = dokan_get_store_info($author->ID); if (!empty($store_info['store_name'])) { ?>
%s', dokan_get_store_url($author->ID), $author->dokan_store_name); ?>
__('Video', 'dexolix'), 'priority' => 50, 'callback' => 'video_tab_content' ); // Add FAQ tab after video $tabs['faq_tab'] = array( 'title' => __('FAQ', 'dexolix'), 'priority' => 60, 'callback' => 'faq_tab_content' ); return $tabs; } add_filter('woocommerce_product_tabs', 'dexolix_woocommerce_product_tabs'); /** * Video tab content */ function video_tab_content() { // Get the product video (you can store this in a custom field) $tab_video_title = get_post_meta(get_the_ID(), 'tab_video_title', true); $tab_video_description = get_post_meta(get_the_ID(), 'tab_video_description', true); $tab_video_image = get_post_meta(get_the_ID(), 'tab_video_image', true); $tab_video_link = get_post_meta(get_the_ID(), 'tab_video_link', true); ?>
1 ? '' : 'show'; $collapsed = $i > 1 ? 'collapsed' : ''; ?>
cart->is_empty(); $cart_url = wc_get_cart_url(); $checkout_url = wc_get_checkout_url(); $cart_number = WC()->cart->get_cart_contents_count(); ob_start(); ?>
cart->get_cart() as $cart_item_key => $cart_item): $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); if (!($_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters('woocommerce_cart_item_visible', true, $cart_item, $cart_item_key))) { continue; } $product_permalink = apply_filters('woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink($cart_item) : '', $cart_item, $cart_item_key); ?>
get_image(), $cart_item, $cart_item_key); ?>
', esc_url(wc_get_cart_remove_url($cart_item_key)), esc_html__('Remove this item', 'dexolix'), $cart_item_key), $cart_item_key); ?>
get_name(), $cart_item, $cart_item_key); ?>
cart->get_product_price($_product), $cart_item, $cart_item_key); ?>
is_sold_individually()) { $product_quantity = '
1
'; } else { $product_quantity = woocommerce_quantity_input(array( 'input_name' => "cart[{$cart_item_key}][qty]", 'input_value' => $cart_item['quantity'], 'max_value' => $_product->get_max_purchase_quantity(), 'min_value' => '0', 'product_name' => $_product->get_name() ), $_product, false); } echo apply_filters('woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item); ?>
cart->get_cart(); if (isset($cart[$cart_item_key])) { $qty = apply_filters('woocommerce_stock_amount_cart_item', wc_stock_amount(preg_replace('/[^0-9\.]/', '', $qty)), $cart_item_key); if (!($qty === '' || $qty === $cart[$cart_item_key]['quantity'])) { if (!($cart[$cart_item_key]['data']->is_sold_individually() && $qty > 1)) { WC()->cart->set_quantity($cart_item_key, $qty, false); $cart_updated = apply_filters('woocommerce_update_cart_action_cart_updated', true); if ($cart_updated) { WC()->cart->calculate_totals(); } } } } WC_AJAX::get_refreshed_fragments(); } } function add_review_title_field_on_comment_form() { echo '
'; } //add_action( 'comment_form_top', 'add_review_title_field_on_comment_form' ); add_action('comment_post', 'save_comment_review_title_field'); function save_comment_review_title_field($comment_id) { if (isset($_POST['title'])) { update_comment_meta($comment_id, 'title', esc_attr($_POST['title'])); } } function get_review_title($id) { $val = get_comment_meta($id, "title", true); $title = $val ? '
' . $val . '
' : ''; return $title; } /***************************** * WooCommerce Plus Minus Quantity Buttons *****************************/ add_action('woocommerce_before_quantity_input_field', 'dexolix_display_quantity_minus'); function dexolix_display_quantity_minus() { echo '
'; } add_action('woocommerce_after_quantity_input_field', 'dexolix_display_quantity_plus'); function dexolix_display_quantity_plus() { echo '
'; } add_action('wp_footer', 'dexolix_add_cart_quantity_plus_minus'); function dexolix_add_cart_quantity_plus_minus() { wc_enqueue_js(" $(document).on( 'click', 'button.plus, button.minus', function() { var qty = $( this ).closest( '.quantity' ).find( '.qty' ); var val = parseFloat(qty.val()); var max = parseFloat(qty.attr( 'max' )); var min = parseFloat(qty.attr( 'min' )); var step = parseFloat(qty.attr( 'step' )); if ( $( this ).is( '.plus' ) ) { if ( max && ( max <= val ) ) { qty.val( max ); } else { qty.val( val + step ); } } else { if ( min && ( min >= val ) ) { qty.val( min ); } else if ( val > 1 ) { qty.val( val - step ); } } }); "); } /* * Hide heading from Single tabs, " Description, Additional Tabs, Review " */ /*add_filter( 'woocommerce_product_description_heading', function ( $heading ) { return null; } ); add_filter( 'woocommerce_product_additional_information_heading', function ( $heading ) { return null; } );*/ /* * Woocommerce Comment Style one * gravatar image size change */ $comment_style_class = cs_get_option('woocommerce_comment_style') ?? ""; if ($comment_style_class === 'style-1') { function dexolix_woocommerce_review_gravatar_size($args): string { return $args = '130'; } add_filter('woocommerce_review_gravatar_size', 'dexolix_woocommerce_review_gravatar_size'); } /** * Woocommerce related product */ function dexolix_get_related_products($product_id, $limit = 4): void { // Get the current product's categories $product = wc_get_product($product_id); $categories = $product->get_category_ids(); // Array of category IDs // Set up the query arguments $args = array( 'post_type' => 'product', 'posts_per_page' => $limit, 'post__not_in' => array($product_id), // Exclude the current product 'orderby' => 'rand', // Random order 'tax_query' => array( array( 'taxonomy' => 'product_cat', // Product categories 'field' => 'term_id', // Match category IDs 'terms' => $categories, ), ), ); // Run the query $related_products = new WP_Query($args); // Display the products if ($related_products->have_posts()) { while ($related_products->have_posts()) { $related_products->the_post(); echo '
'; wc_get_template_part('product-style/product-style', '1'); // Use WooCommerce template parts echo '
'; } } // Reset post data wp_reset_postdata(); } /** * Woocommerce related product With slider */ function dexolix_get_related_products_with_slider($product_id, $limit = 4): void { // Get the current product's categories $product = wc_get_product($product_id); $categories = $product->get_category_ids(); // Array of category IDs // Set up the query arguments $args = array( 'post_type' => 'product', 'posts_per_page' => $limit, 'post__not_in' => array($product_id), // Exclude the current product 'orderby' => 'rand', // Random order 'tax_query' => array( array( 'taxonomy' => 'product_cat', // Product categories 'field' => 'term_id', // Match category IDs 'terms' => $categories, ), ), ); // Run the query $related_products = new WP_Query($args); // Display the products if ($related_products->have_posts()) { while ($related_products->have_posts()) { $related_products->the_post(); echo '
'; wc_get_template_part('product-style/product-style', '1'); // Use WooCommerce template parts echo '
'; } } // Reset post data wp_reset_postdata(); } /*Woocommerce Product single gallery slider image size change*/ add_filter('woocommerce_gallery_image_size', 'dexolix_woocommerce_single_product_image_thumbnail_html'); function dexolix_woocommerce_single_product_image_thumbnail_html($args) { return $args = "full"; }