✏️ 正在编辑: content-product.php
路径:
/home/h359620/public_html/wp-content/themes/datis/woocommerce/content-product.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * The template for displaying product content within loops * * This template can be overridden by copying it to yourtheme/woocommerce/content-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 9.4.0 */ if (! defined('ABSPATH')) { exit; // Exit if accessed directly. } /** @var WC_Product $product */ global $product; if (empty($product) || ! $product->is_visible()) { return; } // Raw numeric prices. $regular_price = (float) $product->get_regular_price(); $sale_price = (float) $product->get_sale_price(); // Product is considered "on sale" only when valid numeric prices exist and sale < regular. $on_sale = $product->is_on_sale() && $regular_price > 0 && $sale_price > 0 && $sale_price < $regular_price; // Discount percentage (e.g. 15 for 15%). $discount = $on_sale ? (int) round(($regular_price - $sale_price) / $regular_price * 100) : 0; // Current price displayed in main price slot: // - If on sale → sale price // - Otherwise → regular price $current_price = $on_sale && $sale_price > 0 ? $sale_price : $regular_price; $display_price = wc_get_price_to_display($product); $price_html = wc_price($display_price); ?> <div <?php wc_product_class('datis-product-card style-1', $product); ?>> <div class="product-wrapper"> <?php // Optional: extra wrappers/badges before card. // do_action( 'woocommerce_before_shop_loop_item' ); ?> <a class="product-thumb" href="<?php the_permalink(); ?>"> <?php // Product thumbnail. echo $product->get_image('woocommerce_thumbnail'); ?> <?php if ($on_sale && $discount > 0) : ?> <span class="discount-percentage"> <?php echo esc_html($discount); ?>% </span> <?php endif; ?> </a> <div class="product-card-content"> <a href="<?php the_permalink(); ?>"> <h3 class="product-title"> <?php echo esc_html(get_the_title()); ?> </h3> </a> <!-- Decorative SVG divider (kept as in original design) --> <svg width="255" height="6" viewBox="0 0 255 6" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M0.000325441 2.66663C0.000325441 4.13939 1.19423 5.33329 2.66699 5.33329C4.13975 5.33329 5.33366 4.13939 5.33366 2.66663C5.33366 1.19387 4.13975 -4.07696e-05 2.66699 -4.07696e-05C1.19423 -4.07696e-05 0.000325441 1.19387 0.000325441 2.66663ZM2.66699 2.66663V3.16663H254.667V2.66663V2.16663H2.66699V2.66663Z" fill="var(--datis-primary-color)" fill-opacity="0.2" /> </svg> <div class="product-price-wrapper"> <?php if ($product->is_type('simple')) : ?> <!-- Current price (sale price if on sale, otherwise regular price) This is the ONLY place where the currency symbol is shown. --> <div class="product-price"> <?php if ($current_price > 0) { // Use full wc_price() output including currency symbol. echo wp_kses_post(wc_price($current_price)); } ?> </div> <!-- Original regular price (only shown when the product is on sale) NOTE: currency symbol is intentionally NOT printed here. --> <?php if ($on_sale && $regular_price > 0) : ?> <div class="regular-price"> <?php // Render only the numeric part (no currency symbol). $regular_price_html = wc_price( $regular_price, [ 'currency' => '', 'price_format' => '%2$s', // only amount, no symbol. ] ); echo wp_kses_post($regular_price_html); ?> </div> <?php endif; ?> <?php elseif ($product->is_type('variable')) : ?> <div class="product-price"> <?php echo $price_html; ?> </div> <?php endif; ?> </div> <?php // No "add to cart" button or other default loop actions: // do_action( 'woocommerce_after_shop_loop_item' ); ?> </div><!-- .product-card-content --> </div><!-- .product-wrapper --> </div>
💾 保存文件
← 返回文件管理器