✏️ 正在编辑: content-single-product.php
路径:
/home/h359620/public_html/wp-content/themes/datis/woocommerce/content-single-product.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * The template for displaying product content in the single-product.php template * * This template can be overridden by copying it to yourtheme/woocommerce/content-single-product.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://woocommerce.com/document/template-structure/ * @package WooCommerce\Templates * @version 3.6.0 */ get_header(); global $product; if (!$product instanceof WC_Product) { $product = wc_get_product(get_the_ID()); } $main_image_id = $product ? $product->get_image_id() : 0; $gallery_ids = $product ? $product->get_gallery_image_ids() : []; $image_ids = []; if ($main_image_id) { $image_ids[] = (int) $main_image_id; } if (!empty($gallery_ids)) { foreach ($gallery_ids as $gid) { $gid = (int) $gid; if ($gid && !in_array($gid, $image_ids, true)) { $image_ids[] = $gid; } } } if (empty($image_ids)) { $image_ids = []; } $discount_percent = null; if ($product && $product->is_on_sale()) { if ($product->is_type('variable')) { $regular = (float) $product->get_variation_regular_price('max'); $sale = (float) $product->get_variation_sale_price('min'); if ($regular > 0 && $sale > 0 && $sale < $regular) { $discount_percent = (int) round((($regular - $sale) / $regular) * 100); } } else { $regular = (float) $product->get_regular_price(); $sale = (float) $product->get_sale_price(); if ($regular > 0 && $sale > 0 && $sale < $regular) { $discount_percent = (int) round((($regular - $sale) / $regular) * 100); } } } $avg_rating = $product ? (float) $product->get_average_rating() : 0; $review_count = $product ? (int) $product->get_review_count() : 0; $avg_display = $avg_rating > 0 ? wc_format_decimal($avg_rating, 1) : wc_format_decimal(0, 1); $top_middle = (array) get_post_meta($product->get_id(), '_datis_attr_top_middle', true); $top_left = (array) get_post_meta($product->get_id(), '_datis_attr_top_left', true); $product_attributes = $product->get_attributes(); if ($product instanceof WC_Product) { $regular_price_html = ''; $sale_price_html = ''; $badge_percent = ''; if ($product->is_type('variable')) { $regular = (float) $product->get_variation_regular_price('min'); $sale = (float) $product->get_variation_sale_price('min'); } else { $regular = (float) $product->get_regular_price(); $sale = (float) $product->get_sale_price(); } if ($regular > 0 && $sale > 0 && $sale < $regular) { $percent = (int) round((($regular - $sale) / $regular) * 100); $badge_percent = $percent . '%'; } $currency_symbol = get_woocommerce_currency_symbol(); $regular_price_html = $regular > 0 ? wc_price($regular) : ''; $sale_price_html = $sale > 0 ? wc_price($sale) : ''; } $demo = get_option('datis_active_demo'); $heading_icon = ''; if ($demo === 'business') : $heading_icon = '<svg width="18" height="69" viewBox="0 0 18 69" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M9 19.8558L10.8558 18L9 16.1442L7.14423 18L9 19.8558ZM9 18L9.32143 18L9.32143 -1.40501e-08L9 0L8.67857 1.40501e-08L8.67857 18L9 18Z" fill="#0A2647" fill-opacity="0.2"/> <path d="M0.322266 39.2267C0.322266 40.7192 1.53224 41.9292 3.02481 41.9292H14.1728C15.6654 41.9292 16.8753 40.7192 16.8753 39.2267V35.7801C16.8753 34.0703 15.3076 32.7902 13.6324 33.1321L2.48441 35.4072C1.22608 35.664 0.322266 36.7709 0.322266 38.0552V39.2267Z" fill="#0A2647"/> <path d="M16.875 28.4159C16.875 26.9233 15.665 25.7134 14.1725 25.7134H3.02447C1.53189 25.7134 0.321926 26.9233 0.321926 28.4159V31.8625C0.321926 33.5722 1.88964 34.8523 3.56487 34.5105L14.7129 32.2354C15.9712 31.9786 16.875 30.8717 16.875 29.5874V28.4159Z" fill="var(--datis-primary-color)"/> <path d="M9 48.2868L10.8558 50.1426L9 51.9983L7.14423 50.1426L9 48.2868ZM9 50.1426L9.32143 50.1426L9.32143 68.1426L9 68.1426L8.67857 68.1426L8.67857 50.1426L9 50.1426Z" fill="#0A2647" fill-opacity="0.2"/> </svg>'; elseif ($demo === 'industry') : $heading_icon = '<svg width="5" height="62" viewBox="0 0 5 62" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M0 0C2.76142 0 5 2.23858 5 5V57C5 59.7614 2.76142 62 0 62V0Z" fill="var(--datis-secondary-color)"/> </svg>'; else : $heading_icon = '<svg width="84" height="15" viewBox="0 0 84 15" fill="none" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_633_2489)"> <rect width="84" height="15" rx="7.5" fill="var(--datis-primary-color)"/> <rect x="-10" width="75" height="15" rx="7.5" fill="var(--datis-secondary-color)"/> </g> <defs> <clipPath id="clip0_633_2489"> <rect width="84" height="15" rx="7.5" fill="white"/> </clipPath> </defs> </svg>'; endif; $approved_count = get_comments_number(get_the_ID()); $product_id = get_the_ID(); $mgr = class_exists('Datis_WC_Wishlist') ? Datis_WC_Wishlist::get_instance() : null; $is_fav = ($mgr && is_user_logged_in()) ? $mgr->is_product_in_wishlist($product_id) : false; ?> <div class="container product-layout mt-4 mt-lg-5 pt-lg-3"> <div class="product-layout-row d-flex flex-column align-items-start gap-3 flex-lg-row justify-content-start"> <aside class="col-12 col-lg-4 product-layout-gallery"> <div class="gallery-main position-relative"> <!-- MAIN --> <div class="swiper gallery-swiper"> <div class="swiper-wrapper"> <?php if (!empty($image_ids)) : ?> <?php foreach ($image_ids as $img_id) : ?> <?php $main_src = wp_get_attachment_image_src($img_id, 'woocommerce_single'); if (empty($main_src[0])) { continue; } $alt = get_post_meta($img_id, '_wp_attachment_image_alt', true); if ($alt === '') { $alt = get_the_title($img_id); } ?> <div class="swiper-slide"> <img class="img-fluid gallery-image" src="<?php echo esc_url($main_src[0]); ?>" alt="<?php echo esc_attr($alt); ?>"> </div> <?php endforeach; ?> <?php endif; ?> </div> </div> <!-- optional --> <?php if ($discount_percent !== null) : ?> <span class="gallery-badge"><?php echo esc_html($discount_percent); ?>%</span> <?php endif; ?> <div class="gallery-actions d-flex flex-column justify-content-between align-items-center gap-2"> <div class="gallery-actions-hover"> <button class="btn btn-share"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M12 3C10.3431 3 9 4.34315 9 6C9 7.65685 10.3431 9 12 9C13.6569 9 15 7.65685 15 6" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> <path d="M5.5 15C7.15685 15 8.5 16.3431 8.5 18C8.5 19.6569 7.15685 21 5.5 21C3.84315 21 2.5 19.6569 2.5 18" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> <path d="M18.5 21C16.8431 21 15.5 19.6569 15.5 18C15.5 16.3431 16.8431 15 18.5 15C20.1569 15 21.5 16.3431 21.5 18" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> <path d="M20 13C20 10.6106 18.9525 8.46589 17.2916 7M4 13C4 10.6106 5.04752 8.46589 6.70838 7M10 20.748C10.6392 20.9125 11.3094 21 12 21C12.6906 21 13.3608 20.9125 14 20.748" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> </svg> </button> <div class="share-wrapper"> <?php esc_html_e('Share', 'datis'); ?> </div> </div> <div class="gallery-actions-hover"> <button class="btn favorite <?php echo $is_fav ? 'is-active' : ''; ?>" type="button" data-datis-wishlist-btn="1" data-product-id="<?php echo esc_attr($product_id); ?>" aria-pressed="<?php echo $is_fav ? 'true' : 'false'; ?>"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path class="favorite-stroke" d="M8.10627 18.2468C5.29819 16.0833 2 13.5422 2 9.1371C2 4.27416 7.50016 0.825464 12 5.50063L14 7.49928C14.2929 7.79212 14.7678 7.79203 15.0607 7.49908C15.3535 7.20614 15.3534 6.73127 15.0605 6.43843L13.1285 4.50712C17.3685 1.40309 22 4.67465 22 9.1371C22 13.5422 18.7018 16.0833 15.8937 18.2468C15.6019 18.4717 15.3153 18.6925 15.0383 18.9109C14 19.7294 13 20.5 12 20.5C11 20.5 10 19.7294 8.96173 18.9109C8.68471 18.6925 8.39814 18.4717 8.10627 18.2468Z" fill="currentColor" /> </svg> </button> <div class="favorite-wrapper"> <?php echo esc_html_x('Favorite', 'Single product favorite label', 'datis'); ?> </div> </div> </div> </div> <!-- THUMBS --> <div class="swiper gallery-thumbs mt-3"> <div class="swiper-wrapper"> <?php if (!empty($image_ids)) : ?> <?php foreach ($image_ids as $img_id) : ?> <?php $thumb_src = wp_get_attachment_image_src($img_id, 'woocommerce_thumbnail'); if (empty($thumb_src[0])) { continue; } $alt = get_post_meta($img_id, '_wp_attachment_image_alt', true); if ($alt === '') { $alt = get_the_title($img_id); } ?> <div class="swiper-slide"> <img class="img-fluid thumb-image" src="<?php echo esc_url($thumb_src[0]); ?>" alt="<?php echo esc_attr($alt); ?>"> </div> <?php endforeach; ?> <?php endif; ?> </div> </div> </aside> <main class="col-12 col-lg-5 product-layout-summary"> <h1 class="product-title"> <?php the_title(); ?> </h1> <div class="rating-statistics d-flex flex-row align-items-center gap-1 mt-2"> <span class="rating d-flex flex-row align-items-center"> <?php echo esc_html($avg_display); ?> <svg width="18" height="18" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_713_2856)"> <path d="M3.52339 4.53364C2.08858 4.85828 1.37117 5.0206 1.20049 5.56947C1.02981 6.11834 1.51889 6.69025 2.49705 7.83408L2.75011 8.13001C3.02807 8.45505 3.16706 8.61757 3.22958 8.81863C3.2921 9.01969 3.27109 9.23653 3.22907 9.6702L3.19081 10.065C3.04292 11.5911 2.96898 12.3542 3.41583 12.6934C3.86268 13.0326 4.53439 12.7234 5.8778 12.1048L6.22536 11.9448C6.60712 11.769 6.79799 11.6811 7.00033 11.6811C7.20266 11.6811 7.39354 11.769 7.77529 11.9448L8.12285 12.1048C9.46627 12.7234 10.138 13.0326 10.5848 12.6934C11.0317 12.3542 10.9577 11.5911 10.8098 10.065M11.5036 7.83408C12.4818 6.69025 12.9708 6.11834 12.8002 5.56947C12.6295 5.0206 11.9121 4.85828 10.4773 4.53364L10.1061 4.44965C9.69833 4.3574 9.49447 4.31128 9.33078 4.18701C9.16709 4.06275 9.0621 3.87442 8.85214 3.49776L8.66098 3.15484C7.9221 1.82937 7.55266 1.16663 7.00033 1.16663C6.44799 1.16663 6.07855 1.82937 5.33967 3.15485" stroke="var(--datis-secondary-color)" stroke-linecap="round" /> </g> <defs> <clipPath id="clip0_713_2856"> <rect width="14" height="14" rx="5" fill="white" /> </clipPath> </defs> </svg> </span> <div class="ratings-number"> <?php echo esc_html( sprintf( __('(Rating from %s customers)', 'datis'), number_format_i18n($review_count) ) ); ?> </div> </div> <div class="product-features"> <p class="product-features-heading mt-4 mb-2 pb-1"> <?php echo esc_html__('Product features', 'datis'); ?> </p> <div class="product-features-wrapper d-flex flex-row flex-wrap gap-2"> <?php foreach ($product_attributes as $attr_obj) : ?> <?php if (!is_a($attr_obj, 'WC_Product_Attribute')) { continue; } // THIS is the real key we saved (pa_color OR custom name like "وزن :") $attr_name = $attr_obj->get_name(); if (empty($top_middle[$attr_name])) { continue; } // Label $label = $attr_obj->is_taxonomy() ? wc_attribute_label($attr_name) : $attr_name; // Value if ($attr_obj->is_taxonomy()) { $terms = wc_get_product_terms($product->get_id(), $attr_name, ['fields' => 'names']); $value = !empty($terms) ? implode(' , ', $terms) : ''; } else { $options = $attr_obj->get_options(); $value = !empty($options) ? implode(' , ', $options) : ''; } if ($label === '' || $value === '') { continue; } ?> <div class="product-features-item"> <p class="features-name"><?php echo esc_html($label); ?></p> <p class="features-value"><?php echo esc_html($value); ?></p> </div> <?php endforeach; ?> </div> <div class="more-features d-flex align-items-center justify-content-center gap-3 mt-4 pt-2"> <span class="more-features-separator"></span> <a href="#specs"><?php echo esc_html__('View all specifications', 'datis'); ?></a> <span class="more-features-separator"></span> </div> </div> </main> <aside class="col-12 col-lg-3 product-layout-purchase"> <div class="product-attributes d-flex flex-column gap-4"> <?php foreach ($product_attributes as $attr_obj) : ?> <?php if (!is_a($attr_obj, 'WC_Product_Attribute')) { continue; } $attr_name = $attr_obj->get_name(); if (empty($top_left[$attr_name])) { continue; } $label = $attr_obj->is_taxonomy() ? wc_attribute_label($attr_name) : $attr_name; if ($attr_obj->is_taxonomy()) { $terms = wc_get_product_terms($product->get_id(), $attr_name, ['fields' => 'names']); $value = !empty($terms) ? implode(' , ', $terms) : ''; } else { $options = $attr_obj->get_options(); $value = !empty($options) ? implode(' , ', $options) : ''; } if ($label === '' || $value === '') { continue; } ?> <div class="product-attribute-item d-flex flex-lg-row align-items-center justify-content-between"> <div class="attribute-name"><?php echo esc_html($label); ?> :</div> <div class="attribute-value"><?php echo esc_html($value); ?></div> </div> <?php endforeach; ?> </div> <?php if ($product->is_type('simple')) : ?> <div class="product-price d-flex mt-4 d-flex flex-lg-row align-items-start justify-content-between"> <div class="price-header d-flex flex-column align-items-start gap-1"> <?php echo esc_html__('Product price:', 'datis'); ?> <?php if (!empty($badge_percent)) : ?> <span class="price-badge"><?php echo esc_html($badge_percent); ?></span> <?php endif; ?> </div> <div class="price-value d-flex flex-column align-items-end"> <?php if (!empty($regular_price_html) && !empty($sale_price_html)) : ?> <span class="regular-price"> <?php echo wp_kses_post($regular_price_html); ?> </span> <div class="price-amount gap-1 d-flex flex-lg-row align-items-center justify-content-start"> <?php echo wp_kses_post($sale_price_html); ?> </div> <?php elseif (!empty($regular_price_html)) : ?> <div class="price-amount gap-1 d-flex flex-lg-row align-items-center justify-content-start"> <?php echo wp_kses_post($regular_price_html); ?> </div> <?php else : ?> <div class="price-amount gap-1 d-flex flex-lg-row align-items-center justify-content-start"> <?php echo esc_html__('Price not available', 'datis'); ?> </div> <?php endif; ?> </div> </div> <div class="product-purchase-separator"></div> <?php if ($product instanceof WC_Product) : ?> <?php if ($product->is_purchasable() && $product->is_in_stock()) : ?> <form class="cart d-flex flex-row align-items-center justify-content-between" action="<?php echo esc_url(apply_filters('woocommerce_add_to_cart_form_action', $product->get_permalink())); ?>" method="post" enctype="multipart/form-data"> <div class="qty-control" data-qty-control> <button type="button" class="qty-btn qty-plus" aria-label="<?php echo esc_attr__('Increase quantity', 'datis'); ?>"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <g opacity="0.6"> <path d="M6 12H18" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> <path d="M12 18V6" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> </g> </svg> </button> <?php // quantity input (Woo-compatible) woocommerce_quantity_input([ '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' => max(1, $product->get_min_purchase_quantity()), 'classes' => ['quantity'], // keeps your class ], $product, true); ?> <button type="button" class="qty-btn qty-minus" aria-label="<?php echo esc_attr__('Decrease quantity', 'datis'); ?>"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <g opacity="0.6"> <path d="M6 12H18" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> </g> </svg> </button> </div> <button type="submit" name="add-to-cart" value="<?php echo esc_attr($product->get_id()); ?>" class="single_add_to_cart_button button alt add-to-cart"> <span class="add-to-cart-icon" aria-hidden="true"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M3 14V10C3 6.22876 3 4.34315 4.17157 3.17157C5.34315 2 7.22876 2 11 2H13C16.7712 2 18.6569 2 19.8284 3.17157C20.4816 3.82476 20.7706 4.69989 20.8985 6M21 10V14C21 17.7712 21 19.6569 19.8284 20.8284C18.6569 22 16.7712 22 13 22H11C7.22876 22 5.34315 22 4.17157 20.8284C3.51839 20.1752 3.22937 19.3001 3.10149 18" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> <path d="M8 14H13" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> <path d="M8 10H9M16 10H12" stroke="var(--datis-primary-color)" stroke-width="1.5" stroke-linecap="round" /> </svg> </span> <?php echo esc_html__('Add to cart', 'datis'); ?> </button> <?php do_action('woocommerce_after_add_to_cart_button'); ?> </form> <?php else : ?> <div class="stock out-of-stock"> <?php echo esc_html__('Out of stock', 'datis'); ?> </div> <?php endif; ?> <?php endif; ?> <?php elseif ($product->is_type('variable')) : ?> <form class="variations_form cart add-to-cart-row" action="<?php echo esc_url(apply_filters('woocommerce_add_to_cart_form_action', $product->get_permalink())); ?>" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint($product->get_id()); ?>" data-product_variations="<?php echo esc_attr(wc_esc_json(wp_json_encode($product->get_available_variations()))); ?>"> <?php woocommerce_variable_add_to_cart(); ?> </form> <?php endif; ?> </aside> </div> <nav class="product-section-nav mt-5"> <div class="section-nav d-flex align-items-center gap-3"> <a class="section-nav-item is-active" href="#intro"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M18 6.00002V6.75002H18.75V6.00002H18ZM15.7172 2.32614L15.6111 1.58368L15.7172 2.32614ZM4.91959 3.86865L4.81353 3.12619H4.81353L4.91959 3.86865ZM5.07107 6.00002V6.75002H18V6.00002V5.25002H5.07107V6.00002ZM18 6.00002H18.75V4.30604H18H17.25V6.00002H18ZM15.7172 2.32614L15.6111 1.58368L4.81353 3.12619L4.91959 3.86865L5.02566 4.61111L15.8232 3.0686L15.7172 2.32614ZM4.91959 3.86865L4.81353 3.12619C3.91638 3.25435 3.25 4.0227 3.25 4.92895H4H4.75C4.75 4.76917 4.86749 4.63371 5.02566 4.61111L4.91959 3.86865ZM18 4.30604H18.75C18.75 2.63253 17.2678 1.34701 15.6111 1.58368L15.7172 2.32614L15.8232 3.0686C16.5763 2.96103 17.25 3.54535 17.25 4.30604H18ZM5.07107 6.00002V5.25002C4.89375 5.25002 4.75 5.10627 4.75 4.92895H4H3.25C3.25 5.9347 4.06532 6.75002 5.07107 6.75002V6.00002Z" fill="var(--datis-primary-color)" fill-opacity="0.6" /> <path d="M8 12H16" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> <path d="M8 15.5H13.5" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> <path d="M4 6V19C4 20.6569 5.34315 22 7 22H17C18.6569 22 20 20.6569 20 19V14M4 6V5M4 6H17C18.6569 6 20 7.34315 20 9V10" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> </svg> <?php esc_html_e('Introduction', 'datis'); ?> </a> <a class="section-nav-item" href="#specs"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M2 5.5L3.21429 7L7.5 3" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> <path d="M2 12.5L3.21429 14L7.5 10" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> <path d="M2 19.5L3.21429 21L7.5 17" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> <path d="M22 12H17M12 12H13.5" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> <path d="M12 19H17M20.5 19H22" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> <path d="M22 5L12 5" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> </svg> <?php esc_html_e('Specifications', 'datis'); ?> </a> <a class="section-nav-item" href="#reviews"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M14 7.07026C12.8233 6.38958 11.4571 6 10 6C5.58172 6 2 9.58172 2 14C2 15.2797 2.30049 16.4893 2.83477 17.562C2.97675 17.847 3.02401 18.1729 2.94169 18.4805L2.46521 20.2613C2.25836 21.0344 2.96561 21.7416 3.73868 21.5348L5.51951 21.0583C5.82715 20.976 6.15297 21.0233 6.43802 21.1652C7.51069 21.6995 8.72025 22 10 22C14.4183 22 18 18.4183 18 14C18 12.5429 17.6104 11.1767 16.9297 10" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> <path d="M18 14.5018C18.0665 14.4741 18.1324 14.4453 18.1977 14.4155C18.5598 14.2501 18.9661 14.1882 19.3506 14.2911L19.8267 14.4185C20.793 14.677 21.677 13.793 21.4185 12.8267L21.2911 12.3506C21.1882 11.9661 21.2501 11.5598 21.4155 11.1977C21.7908 10.376 22 9.46242 22 8.5C22 7.22592 21.6334 6.03745 21 5.03431M9.5 5.9956C10.4806 3.64899 12.7977 2 15.5 2C16.7886 2 17.9897 2.375 19 3.02182" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="1.5" stroke-linecap="round" /> <path d="M6.51779 14H6.52679M10.0085 14H10.0175M13.4995 14H13.5085" stroke="var(--datis-primary-color)" stroke-opacity="0.6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" /> </svg> <?php esc_html_e('Reviews', 'datis'); ?> </a> </div> </nav> <div id="intro" class="mt-4"> <div class="product-intro-content entry-content"> <?php the_content(); ?> </div> <?php $cat_terms = get_the_terms(get_the_ID(), 'product_cat'); $tag_terms = get_the_terms(get_the_ID(), 'product_tag'); $has_cats = !empty($cat_terms) && !is_wp_error($cat_terms); $has_tags = !empty($tag_terms) && !is_wp_error($tag_terms); ?> <?php if ($has_cats) : ?> <div class="product-cat d-flex flex-row flex-wrap align-items-center gap-4 mt-4"> <p><?php echo esc_html__('Categories:', 'datis'); ?></p> <ul class="d-flex flex-row flex-wrap align-items-center gap-2"> <?php foreach ($cat_terms as $term) : ?> <li> <a href="<?php echo esc_url(get_term_link($term)); ?>"> <?php echo esc_html($term->name); ?> </a> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?> <?php if ($has_cats && $has_tags) : ?> <div class="intro-separator my-2"></div> <?php endif; ?> <?php if ($has_tags) : ?> <div class="product-tags d-flex flex-row flex-wrap align-items-center gap-4"> <p><?php echo esc_html__('Tags:', 'datis'); ?></p> <ul class="d-flex flex-row flex-wrap align-items-center gap-2"> <?php foreach ($tag_terms as $term) : ?> <li> <a href="<?php echo esc_url(get_term_link($term)); ?>"> <?php echo esc_html($term->name); ?> </a> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?> </div> <?php /** @var WC_Product $product */ $product_attributes = $product ? $product->get_attributes() : []; $spec_rows = []; // [ ['label'=>'...', 'value'=>'...'], ... ] foreach ($product_attributes as $attr_obj) { if (! is_a($attr_obj, 'WC_Product_Attribute')) { continue; } // فقط اونایی که "نمایش در برگه محصول" تیک خورده if (! $attr_obj->get_visible()) { continue; } $attr_name = $attr_obj->get_name(); // Label $label = $attr_obj->is_taxonomy() ? wc_attribute_label($attr_name) : $attr_name; // Value if ($attr_obj->is_taxonomy()) { $terms = wc_get_product_terms($product->get_id(), $attr_name, ['fields' => 'names']); $value = ! empty($terms) ? implode(' , ', $terms) : ''; } else { $options = $attr_obj->get_options(); $value = ! empty($options) ? implode(' , ', $options) : ''; } if ($label === '' || $value === '') { continue; } $spec_rows[] = [ 'label' => $label, 'value' => $value, ]; } if (! empty($spec_rows)) : ?> <div id="specs" class="mt-5"> <h3><?php echo esc_html__('Specifications', 'datis'); ?></h3> <table class="table table-borderless specs-table"> <tbody> <?php foreach ($spec_rows as $row) : ?> <tr class="d-flex flex-column flex-lg-row mb-4"> <th class="col-12 col-lg-3 specs-name"> <?php echo esc_html($row['label']); ?> : </th> <td class="col-12 col-lg-9 specs-value"> <?php echo esc_html($row['value']); ?> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> <div id="reviews"> <?php if ($approved_count > 0) : ?> <div class="product-comments mt-5 my-lg-5 py-lg-5"> <div class="heading d-flex flex-row justify-content-between align-items-center gap-3 mb-4"> <?php if ($demo === 'business' || $demo === 'industry') : ?> <div class="d-flex flex-row align-items-center gap-3"> <?php else : ?> <div class="d-flex flex-column align-items-start gap-3"> <?php endif; ?> <?php echo $heading_icon; ?> <div class="d-flex flex-column"> <?php if ($demo === 'industry') : ?> <p> <?php printf( wp_kses_post(__("%s reviews", 'datis')), '<span class="accent-text">' . esc_html__("Our customers'", 'datis') . '</span>' ); ?> </p> <span>REVIEWS</span> <?php else : ?> <p><?php esc_html_e("Our customers' reviews", 'datis'); ?></p> <span><?php esc_html_e('REVIEWS', 'datis'); ?></span> <?php endif; ?> </div> </div> <?php if ($demo === 'business' || $demo === 'industry') : ?> <svg width="950" height="6" viewBox="0 0 950 6" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M-3.26633e-05 2.88672L2.88672 5.77347L5.77347 2.88672L2.88672 -3.26633e-05L-3.26633e-05 2.88672ZM2.88672 2.88672V3.38672H949.887V2.88672V2.38672H2.88672V2.88672Z" fill="#0A2647" fill-opacity="0.1" /> </svg> <?php endif; ?> </div> <?php datis_comments_list(); ?> </div> <?php endif; ?> <div class="product-comment-form mt-5 pt-lg-5"> <div class="heading d-flex flex-row justify-content-between align-items-center gap-3 mb-4"> <?php if ($demo === 'business' || $demo === 'industry') : ?> <div class="d-flex flex-row align-items-center gap-3"> <?php else : ?> <div class="d-flex flex-column align-items-start gap-3"> <?php endif; ?> <?php echo $heading_icon; ?> <div class="d-flex flex-column"> <?php if ($demo === 'industry') : ?> <p> <?php printf( wp_kses_post(__("Submit a %s", 'datis')), '<span class="accent-text">' . esc_html__("Review", 'datis') . '</span>' ); ?> </p> <span>REVIEWS</span> <?php else : ?> <p><?php esc_html_e("Submit a Review", 'datis'); ?></p> <span><?php esc_html_e('REVIEWS', 'datis'); ?></span> <?php endif; ?> </div> </div> <?php if ($demo === 'business' || $demo === 'industry') : ?> <svg width="950" height="6" viewBox="0 0 950 6" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M-3.26633e-05 2.88672L2.88672 5.77347L5.77347 2.88672L2.88672 -3.26633e-05L-3.26633e-05 2.88672ZM2.88672 2.88672V3.38672H949.887V2.88672V2.38672H2.88672V2.88672Z" fill="#0A2647" fill-opacity="0.1" /> </svg> <?php endif; ?> </div> <div class="col-12 col-lg-9" id="respond"> <?php datis_comments_form(); ?> </div> </div> </div> <?php // Safety: WooCommerce must exist if (!class_exists('WooCommerce')) { return; } // Get extras singleton safely $extras = class_exists('Datis_Theme_Extras') ? Datis_Theme_Extras::get_instance() : null; if (!$extras) { return; } // Demo/icon safe defaults (avoid notices) $demo = isset($demo) ? (string) $demo : ''; $heading_icon = isset($heading_icon) ? $heading_icon : ''; // Get recent categories (support both old/new method names) $terms = []; if (method_exists($extras, 'get_recent_product_categories')) { $terms = $extras->get_recent_product_categories(4); } elseif (method_exists($extras, 'datis_get_recent_product_categories')) { $terms = $extras->datis_get_recent_product_categories(4); } if (empty($terms) || !is_array($terms)) { return; } $first_term = $terms[0] ?? null; if (!$first_term || empty($first_term->term_id)) { return; } // Get products query for first category (support multiple method names) $first_q = null; $term_id = (int) $first_term->term_id; if (method_exists($extras, 'get_products_for_cat_public')) { $first_q = $extras->get_products_for_cat_public($term_id, 4); } elseif (method_exists($extras, 'datis_get_products_for_cat')) { $first_q = $extras->datis_get_products_for_cat($term_id, 4); } elseif (method_exists($extras, 'get_products_for_cat')) { // In case you made it public $first_q = $extras->get_products_for_cat($term_id, 4); } if (!$first_q instanceof WP_Query) { // Fail silently if we couldn't get a proper query return; } // Renderer callback (support multiple method names, with fallback) $render_slide = function ($product) use ($extras) { if (!($product instanceof WC_Product)) return ''; if (method_exists($extras, 'render_product_slide_html_public')) { return (string) $extras->render_product_slide_html_public($product); } if (method_exists($extras, 'datis_render_product_slide_html')) { return (string) $extras->datis_render_product_slide_html($product); } if (method_exists($extras, 'render_product_slide_html')) { // In case you made it public return (string) $extras->render_product_slide_html($product); } // Absolute fallback: render Woo template inside a swiper slide ob_start(); global $post, $product; $old_post = $post ?? null; $old_product = $product ?? null; $post = get_post($product->get_id()); setup_postdata($post); $product = $product; ?> <div class="swiper-slide"> <?php wc_get_template_part('content', 'product'); ?> </div> <?php wp_reset_postdata(); $post = $old_post; $product = $old_product; return ob_get_clean(); }; ?> <div class="datis-recent-cat-section mt-5 pt-5"> <div class="d-flex flex-column flex-lg-row align-items-start align-items-lg-center justify-content-between"> <div class="heading d-flex flex-row justify-content-between align-items-center gap-3"> <?php if ($demo === 'business' || $demo === 'industry') : ?> <div class="d-flex flex-row align-items-center gap-3"> <?php else : ?> <div class="d-flex flex-column align-items-start gap-3"> <?php endif; ?> <?php echo $heading_icon; ?> <div class="d-flex flex-column"> <?php if ($demo === 'industry') : ?> <p> <?php printf( wp_kses_post(__("Our latest %s", 'datis')), '<span class="accent-text">' . esc_html__("products", 'datis') . '</span>' ); ?> </p> <span>OUR PRODUCTS</span> <?php else : ?> <p><?php esc_html_e("Our latest products", 'datis'); ?></p> <span><?php esc_html_e('OUR PRODUCTS', 'datis'); ?></span> <?php endif; ?> </div> </div> </div> <svg class="d-none d-lg-flex" width="400" height="6" viewBox="0 0 350 6" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> <path d="M0.000325441 2.66675C0.000325441 4.13951 1.19423 5.33341 2.66699 5.33341C4.13975 5.33341 5.33366 4.13951 5.33366 2.66675C5.33366 1.19399 4.13975 8.13007e-05 2.66699 8.13007e-05C1.19423 8.13007e-05 0.000325441 1.19399 0.000325441 2.66675ZM2.66699 2.66675V3.16675H349.667V2.66675V2.16675H2.66699V2.66675Z" fill="#0B3D91" fill-opacity="0.2" /> </svg> <div class="datis-cat-tabs-wrap"> <div class="datis-cat-tabs d-flex flex-row justify-content-end flex-lg-wrap flex-nowrap gap-2"> <?php foreach ($terms as $idx => $t) : ?> <?php if (!is_object($t) || empty($t->term_id)) continue; ?> <button type="button" class="datis-cat-tab <?php echo $idx === 0 ? 'is-active' : ''; ?>" data-term-id="<?php echo esc_attr((int) $t->term_id); ?>"> <?php echo esc_html($t->name ?? ''); ?> </button> <?php endforeach; ?> </div> </div> </div> <div class="swiper datis-cat-products-swiper mt-4" data-initial-term="<?php echo esc_attr($term_id); ?>"> <div class="swiper-wrapper"> <?php if ($first_q->have_posts()) : while ($first_q->have_posts()) : $first_q->the_post(); $p = wc_get_product(get_the_ID()); echo $render_slide($p); endwhile; wp_reset_postdata(); endif; ?> </div> </div> </div> </div> <?php get_footer(); ?>
💾 保存文件
← 返回文件管理器