donglang9880 2019-05-27 14:39
浏览 43

如何替换产品页面和商店存档页面中的产品简短描述

I want to replace text in product short description in product page and in shop archive page with different view with custom text and information with shipping class, but not slug, I want to display name of the shipping class

I found some code on this forum, but it doesn't work on shop archive page, and it show slug of shipping class, but not the name

add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary', 2 );
function custom_single_product_summary(){
    global $product;

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
    add_action( 'woocommerce_single_product_summary', 'custom_single_excerpt', 20 );
}

function custom_single_excerpt(){
    global $post, $product;

    $short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );

    if ( ! $short_description )
        return;

    // The custom text
    $custom_text = ' <strong>Forma de pagamento</strong>
    <ul class="fancy-bullet-points red">
    <li>Boleto Bancario</li>
    <li>Cartao de credito em ate 12 parcelas</li>
    <li>Cartao de debito</li>
    <li>PayPal</li>
    </ul>';

    $clase=$product->get_shipping_class();


    ?>
    <div class="woocommerce-product-details__short-description">
        <?php echo $short_description . $custom_text;  // WPCS: XSS ok. ?>
    <?php echo $short_description . $clase;  // WPCS: XSS ok. ?>
    </div>
    <?php
}

add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
    global $product;

    $product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;

    if ( is_single( $product_id ) )
        $post_excerpt = '<p class="some-class">' . __( "", "woocommerce" ) . '</p>';

    return $post_excerpt;
}

I think this two code can be compiled

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大