Woocommerce中的WordPress do_shortcode

时间:2017-08-25 08:39:42

标签: php wordpress woocommerce shortcode

我正在使用do_shortcode挂钩阻止"添加到购物车"显示非付费会员。

我使用了以下代码和"添加到购物车"似乎不起作用。

    else{
echo do_shortcode( '[ihc-hide-content ihc_mb_type="show" ihc_mb_who="1" ihc_mb_template="1" ]' . '<button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>' . '[/ihc-hide-content]" );
');

它显示为:

Output screenshot

1 个答案:

答案 0 :(得分:0)

试试此代码

else{
    echo do_shortcode( 
        '[ihc-hide-content ihc_mb_type="show" ihc_mb_who="1" ihc_mb_template="1" ]' . 
            '<button 
                type="submit" 
                name="add-to-cart" 
                value="
                    '.<?php 
                            esc_attr( $product->get_id() )
                        ?>.'"
                class="single_add_to_cart_button button alt">
                '.<?php 
                    esc_html( $product->single_add_to_cart_text() )
                ?>.'
            </button>' . 
        '[/ihc-hide-content]" );
    ');

更新

else{
    echo do_shortcode( 
        '[ihc-hide-content ihc_mb_type="show" ihc_mb_who="1" ihc_mb_template="1" ]' . 
            '<button 
                type="submit" 
                name="add-to-cart" 
                value="
                    '.
                        esc_attr( $product->get_id() )
                    .'"
                class="single_add_to_cart_button button alt">
                '.
                    esc_html( $product->single_add_to_cart_text() )
                .'
            </button>' . 
        '[/ihc-hide-content]" );
    ');