在 woocommerce 的单个产品页面上如何移动一些文本

问题描述 投票:0回答:1

我希望我正确地问了这个问题。 我正在尝试将“产品状况:翻新”移至“可用性:有库存”下。

from site

<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
/**
 * Adds the human readable product condition
 * to the product meta section.
 *
 * @return string
 */
add_action( 'woocommerce_product_meta_end', 'product_condition_display_product_meta' );
function product_condition_display_product_meta() {
    global $product;
    // Retrieve the product condition for this product
    $product_condition = product_condition_return_selected_condition( $product->get_id() );
    if ( $product_condition ) {
        // Filter for the product condition label
        $label = apply_filters( 'product_condition_display_label', __( 'Product Condition: ', 'product-condition' ), $product->get_id() );
        ?>
        <span class="product_condition_wrapper">
            <span class="product_condition_title"><strong><?php echo esc_html( $label ); ?></strong></span>
            <span class="product_condition">
                <?php
                switch ( $product_condition ) {
                    case 'other':
                    case 'new-other':
                        // Retrieve the custom product condition if it is set in the product settings
                        $custom_condition = get_post_meta( $product->get_id(), 'product_condition_custom_condition', true );
                        echo esc_html( $custom_condition );
                        break;

                    default:
                        echo esc_html( product_condition_options( $product_condition ) );
                        break;
                }
                ?>
            </span>
        </span>

我正在从 Woocommerce 的插件产品条件中编辑此内容。 我将“产品状况”加粗,并将“SellerRefurbished”更改为“Refurbished”。似乎无法让最后一部分工作。

这部分代码来自single-product-page.php:

add_action( 'woocommerce_product_meta_end', 'product_condition_display_product_meta' );

我相信我需要删除(remove_action)它并以某种方式用不同的优先级替换这个 woocommerce_product_meta_end 以将其提升到 Availability:inStock 下面。

product add-action
1个回答
0
投票

有两种选择。

  1. 您确实可以删除该操作并再次添加。

    remove_action( 'woocommerce_single_product_summary', 'product_condition_display_product_meta', 25 );
    

    然后,将其添加回不同的钩子:

    add_action( 'woocommerce_single_product_summary', 'product_condition_display_product_meta', 15 );
    

    这会将单个产品页面中显示的产品状况向上移动,位于可用性部分的下方。

    代码片段适用于functions.php 文件或自定义插件。它保留了原始函数的功能,同时更改了它与 WooCommerce 单一产品摘要挂钩的位置。

  2. 无需直接操作 PHP 操作即可实现相同结果的另一种方法是使用自定义 CSS 重新定位产品条件元素。此方法不会改变 HTML 结构或 PHP 代码,而只是调整视觉布局。

    .single-product .product_meta .product_condition_wrapper {
       order: -1; /* to the start */
       margin-bottom: 10px; /* margin as needed */
    }
    
© www.soinside.com 2019 - 2024. All rights reserved.