Woocommerce Hook v 4.6.1 - 如何使用 echo 输出一个或多个字符串

Woocommerce Hook v 4.6.1 - How to output one or more Strings with echo

这是 functions.php 文件中的 Hook。

请问如何输出下面的脚本?

由于该行,我在 debug.log 文件中收到一条错误消息

line 1767 <?php echo do_shortcode('[addthis tool="addthis_inline_share_toolbox_r1xt"]'); ?> 

错误信息:debug.log

[22-Oct-2020 17:22:28 UTC] PHP Parse error:  syntax error, unexpected 'tool' (T_STRING), expecting ']' in C:\xampppserver2\htdocs\mrdigital\wp-content\themes\astra-child\functions.php on line 1767

我在整个脚本中使用了单引号,所以这是冲突原因:

感恩!

add_action( 'woocommerce_order_details_after_order_table', 'box_sharing_social_icons', 10, 1 );

function box_sharing_social_icons($order) {

    echo '
        <!-- start box -->
        <div class="share_pattern">
            <h2 class="woocommerce-column__title">Sharing</h2>
            <div class="content_share d-flex">
            <div><p>Explanation<br>
                Nulla quis lorem ut libero malesuada feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget tortor risus. Donec sollicitudin molestie malesuada. Quisque velit nisi, pretium ut lacinia in, elementum id enim. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Cras ultricies ligula sed magna dictum porta. Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.</p>
                <div class="text-center">
                    <?php echo do_shortcode('[addthis tool="addthis_inline_share_toolbox_r1xt"]'); ?>

                </div>
                
            </div>
            <div>
                <p>Donec rutrum congue leo eget malesuada. Proin eget tortor risus. Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus.</p>
            </div>
            </div>
        </div>

    <?php echo str_repeat("<br>", 1) ?>
    <!-- end box -->
    ';       

}

虽然您没有 post 它,但您几乎肯定会遇到语法错误...请参考实际的错误通知以了解您遇到的问题 运行。行号对我们诊断问题没有太大帮助,因为您的代码段中的行号不相同。

您正在回显字符串文本,因此您没有打开 <?php 标签。删除打开和关闭 PHP 标签的两个实例可能会起作用。或者由于您直接写出 HTML,我可能会关闭 pho 标签...打印 HTML... 然后再次打开 PHP 标签以获取短代码参考。

add_action( 'woocommerce_order_details_after_order_table', 'box_sharing_social_icons', 10, 1 );
function box_sharing_social_icons($order) { ?>

        <!-- start box -->
        <div class="share_pattern">
            <h2 class="woocommerce-column__title">Compartilhar</h2>
            <div class="content_share d-flex">
            <div><p>Explicação<br>
                Nulla quis lorem ut libero malesuada feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget tortor risus. Donec sollicitudin molestie malesuada. Quisque velit nisi, pretium ut lacinia in, elementum id enim. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Cras ultricies ligula sed magna dictum porta. Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.</p>
                <div class="text-center">
                  <?php echo do_shortcode('[addthis tool="addthis_inline_share_toolbox_r1xt"]'); ?>
                </div>
                
            </div>
            <div>
                <p>Donec rutrum congue leo eget malesuada. Proin eget tortor risus. Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus.</p>
            </div>
            </div>
        </div>
    <!-- end box -->
<?php     
}