在woocommerce动作钩子中设置php的样式

时间:2017-10-31 10:21:11

标签: wordpress woocommerce advanced-custom-fields

我正在尝试使用动作挂钩将自定义字段添加到Woocommerce中的my-account页面。这是正确加载自定义字段的页面:

https://blendismoothies.com/my-account/

以下是代码:

render

问题在于造型 - h2& p标签位于内容之下 - 如何让html环​​绕php?

我希望这有道理吗?

3 个答案:

答案 0 :(得分:0)

使用get_field()函数。

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );
    add_action( 'woocommerce_account_dashboard', 'account_custom_area', 1 );
    function account_custom_area () {
             $blendiclubtitle = get_field( "blendi_club_title", $post->ID );
             $blendiclubcontent = get_field('blendi_club_content', $post->ID) ;
            echo "<h2>" . $blendiclubtitle . "</h2>";
            echo "<p class='blendi_club_content'>" . $blendiclubcontent . "</p>";

    };

答案 1 :(得分:0)

请尝试以下代码:

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

add_action( 'woocommerce_account_dashboard', 'account_custom_area', 1 );

function account_custom_area () {
        $blendiclubtitle = the_field('blendi_club_title', 'option') ;
        $blendiclubcontent = the_field('blendi_club_content', 'option') ;
        echo '<h2>' . $blendiclubtitle . '</h2>';
        echo '<p class="blendi_club_content">' . $blendiclubcontent . '</p>';

};

答案 2 :(得分:0)

谢谢你穆罕默德&amp; Shital - 最终解决了这个问题。 ACF所见即所得的自定义字段输出一个p标记,因此将p标记更改为一个div来解决该问题。使用&#39; get_field&#39;而不是&#39; the_field&#39;解决了h2标签的问题。

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );
add_action( 'woocommerce_account_dashboard', 'account_custom_area', 1 );
function account_custom_area () {
         $blendiclubtitle = get_field( 'blendi_club_title', 'option' );
         $blendiclubcontent = get_field('blendi_club_content', 'option') ;
        echo "<h2>" . $blendiclubtitle . "</h2>";
        echo '<div class="blendi_club_content">' . $blendiclubcontent . '</div>';
};