【问题标题】:Display Elementor page to customer in Woocommerce My-Account在 Woocommerce My-Account 中向客户显示 Elementor 页面
【发布时间】:2019-07-17 15:47:06
【问题描述】:

我有 Woocommerce(订阅)和 Elementor。我正在尝试在 Woocommerce 的 Myaccount 区域中添加页面/内容 - 新的导航菜单项。

创建端点和导航菜单位没有问题。我面临的问题是显示在 elementor 中创建的页面。一个页面(也是在 elementor 中创建的)可以正常工作,而另一个则没有。

在 elementor 中创建的页面相当简单,基本上创建了 4 列 10 行。在每一行中都有一个按钮,它使用简码来获取按钮文本和 url,以便在按下时导航到。这一切都经过测试,直接访问页面时可以正常工作。

如果我使用此代码

$post = get_post(1114); 
$content = apply_filters('the_content', $post->post_content); 
echo $content;

在显示页面的端点上,输出只是一个文本行列表,从左到右显示表格单元格。这仅显示按钮文本(没有 URL 符号),并且不会像 elementor 编辑器中的页面那样格式化(或者如果直接访问) 例如,如果表是

H1    H2    H3    H4
R1a   R1b   R1c   R1d
R2a   R2b   R2d   R2d

显示是

H1
H2
H3
R1a
R1b
R1c
R1d
R2a
R2b
R2c
R2d

如果我使用下面的代码

$content = \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( 1119);
echo $content;

表格在很大程度上正确显示所有格式等。一件事不起作用的是按钮文本。它不显示简码返回的文本,而是只显示简码。

我确定我只是遗漏了一些需要在某处处理的东西,但我不知道它是什么,不幸的是 Elementor 页面并没有提供太多信息。

任何帮助将不胜感激。

【问题讨论】:

    标签: wordpress woocommerce woocommerce-subscriptions elementor


    【解决方案1】:

    编辑:正确的答案是在我之前没有注意到的文本字段旁边有一个动态按钮/下拉菜单。使用它您可以选择简码并输入简码详细信息,它将正确显示而无需手动处理。

    不知道为什么它不能像上面那样正确加载,但为了解决这个问题,我做了下面的事情。不确定这是执行此操作的正确方法,但它有效。

    $content = \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( 1013 );
        $content = process_subswitch_content_for_shortcodes( $content );
        echo $content;
    

    以下内容实质上搜索从get_builder_content_for_display 函数返回的内容中的“[subswitch”,它是相关短代码的开始(无法仅搜索 ],因为 element 或将其他 [] 放入内容中)。

    function process_subswitch_content_for_shortcodes( $content ) {
    
        $keepprocessing = true;
        $searchstart_pos = 0;
        do {
    
            $startchar_pos = strpos( $content, "[subswitch", $searchstart_pos );
            if ( $startchar_pos == false ) {
                $keepprocessing = false;
            }
    
            $endchar_pos = strpos( $content, "]", $startchar_pos );
            $shortcode_request = substr( $content, $startchar_pos, $endchar_pos );
            if ( $shortcode_request == false ) {
                $keepprocessing = false;
            }
    
            $shortcode_content = do_shortcode( $shortcode_request );
            $content = str_replace( $shortcode_request, $shortcode_content, $content );
    
            $searchstart_pos = $endchar_pos;
    
        } while ( $keepprocessing ); 
    
        return $content;
    }
    

    我当然还是想知道直接加载它的方式,以便它显示而不必手动处理短代码。

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      • 2020-11-12
      • 1970-01-01
      • 2017-05-24
      • 2018-08-14
      相关资源
      最近更新 更多