移动 Woocommerce 详细描述并将内容隐藏在阅读更多

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

我正在尝试将 Woocommerce 中的长产品描述从主要摘要下方的选项卡移至主要摘要本身内(最好位于“添加到购物车”按钮下方)。

我已取消设置描述选项卡,还删除了简短描述,并将描述移至我想要的位置。完整显示它不是问题。但我也希望能够截断它并将大部分内容隐藏在“阅读更多”链接后面。

在尝试了各种解决方案后,我发现了以下两种情况之一:

a)我可以添加阅读更多内容,但必须删除格式,因此整个描述会作为一个长段落而不是被分解。

b)如果我不去掉格式,“阅读更多”仅适用于第一段,其余内容将显示在“阅读更多”链接之后。

这就是我到目前为止所做的 - 定位描述,在其周围添加一个 div 类,以便它可以被 Javascript 定位,然后使用现有的解决方案来添加阅读更多本身。

add_action( 'woocommerce_single_product_summary', 'custom_template_single_long_description', 30 );
 

function custom_template_single_long_description()
{
    ob_start();
the_content();
$content= ob_get_clean();
echo '<div class="long-description">' . $content. '</div>';
    wc_enqueue_js( '
      var num_chars = 100;
      var replace_ellipses = " ... ";
      var description_content = $(".long-description").html();
      if (description_content.length > num_chars) {
         var a = description_content.substr(0, num_chars);
         var b = description_content.substr(num_chars - description_content.length);
         var html = a + "<span class=\'truncated\'>" + replace_ellipses + "<a class=\'read-more\'>Read more</a></span><span class=\'truncated\' style=\'display:none\'>" + b + "</span>";
         $(".long-description").html(html);
      }
      $(".read-more").click(function(e) {
         e.preventDefault();
         $(".long-description .truncated").toggle();
      });
   ' );
}

这样,前 100 个字符以“阅读更多”结尾,但后续段落将显示在“阅读更多”之后。我希望将其全部隐藏,但也希望在扩展时保持段落中断。

wordpress woocommerce hook-woocommerce
1个回答
0
投票

您可以尝试使用此代码吗?看看这是否有效

<?php
/*
Plugin Name:  woopostreq
Description: Custom actions for WooCommerce.
Version: 1.0
Author: callum
*/

add_action( 'woocommerce_payment_complete', 'so_payment_complete' );

function so_payment_complete( $order_id ) {
    $order = wc_get_order( $order_id );

    $billing_email = $order->get_billing_email();
    $billing_phone = $order->get_billing_phone();
    $order_date = $order->get_date_paid();

    $url = 'http://blanked out/woocommercepost';

    // Prepare the data for the request
    $data = array(
        'orderid' => $order_id,
        'billingemail' => $billing_email,
        'billingphone' => $billing_phone,
        'orderdate' => $order_date
    );

    // Post the request
    wp_remote_post( $url, array(
        'method' => 'POST',
        'timeout' => 45,
        'redirection' => 5,
        'httpversion' => '1.0',
        'blocking' => true,
        'headers' => array(),
        'body' => $data
    ));
}
© www.soinside.com 2019 - 2024. All rights reserved.