【问题标题】:woocommerce displaying instructions for downloadable products only on thank you pagewoocommerce 仅在感谢页面上显示可下载产品的说明
【发布时间】:2015-01-03 18:17:29
【问题描述】:

我是 woocommerce 和 wordpress 的新手,我想要实现的是在感谢页面上仅显示可下载产品的说明。

可能是我错了,但我有这个文件,我正在查看woocommerce->templates->order->order-details.php,它有以下代码在谢谢页面上输出下载链接(我假设我找不到另一个文件这份工作)。

    if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) {
echo 'Click the links below to access your courses. You will also receive an email shortly with the links to download your products.';
        $download_files = $order->get_item_downloads( $item );
        $i              = 0;
        $links          = array();

        foreach ( $download_files as $download_id => $file ) {

            $i++;

            $links[] = '<small style="font-size: 15pt !important;"><a href="' . esc_url( $file['download_url'] ) . '">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_files ) > 1 ? ' ' . $i . ': ' : ': ' ) ) . esc_html( $file['name'] ) . '</a></small>';
        }

        echo '<br/>' . implode( '<br/>', $links );
    }

现在我只想在此处回显可下载产品的文本。但它不显示文本。

我要回显的文字如下红色箭头所指的地方

点击下面的链接访问您的课程。您还将很快收到一封电子邮件,其中包含下载您的产品的链接。;

如果有人能在这方面帮助我,我将不胜感激。

【问题讨论】:

  • 产品的链接是否出现在该页面上?
  • @mevius 如果有帮助,我已经用屏幕截图更新了我的问题
  • 您想在哪里打印该消息?进那张桌子?
  • 看起来您可能正在编辑错误的模板...
  • @Rohil_PHPBeginner 就在表格内“产品”的下方

标签: php wordpress woocommerce


【解决方案1】:

首先确保您已从后端添加可下载文件My guess is, you have not added file。因此,添加来自back end 的任何文件,以便查看您已插入消息

见下图并确保您拥有下图中带有方形框的东西:

执行此操作后,您将能够看到该消息

我的代码同一个文件中:

<td class="product-name">
<?php

    if ( $_product && ! $_product->is_visible() )
    echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item );
    else
    echo apply_filters( 'woocommerce_order_item_name', sprintf( '<a href="%s">%s</a>', get_permalink( $item['product_id'] ), $item['name'] ), $item );

    echo apply_filters( 'woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf( '&times; %s', $item['qty'] ) . '</strong><br>', $item );

    $item_meta->display();

    if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) {
    echo "Click below link to download the file<br>";
    $download_files = $order->get_item_downloads( $item );
    $i              = 0;
    $links          = array();
    foreach ( $download_files as $download_id => $file ) {
    $i++;

    $links[] = '<small><a href="' . esc_url( $file['download_url'] ) . '">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_files ) > 1 ? ' ' . $i . ': ' : ': ' ) ) . esc_html( $file['name'] ) . '</a></small>';
                            }

    echo '<br/>' . implode( '<br/>', $links );
    }
    ?>
    </td>

如果您有任何疑问,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-29
    • 2019-12-04
    • 2021-02-09
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    相关资源
    最近更新 更多