【问题标题】:Hide custom tab WooCommerce (Grouped Product Pages) depending on Child Product attributes根据子产品属性隐藏自定义选项卡 WooCommerce(分组产品页面)
【发布时间】:2016-06-01 00:30:04
【问题描述】:

我已经设置了一些自定义标签来显示分组产品。

add_filter( 'woocommerce_product_tabs', 'woo_paym_product_tab' );

function woo_paym_product_tab( $tabs ) {
    global $post;
    if( function_exists('get_product') ){
        $product = get_product( $post->ID );
        if( $product->is_type( 'grouped' ) ){
            $tabs['paym-plans'] = array( 'title' => __( 'Contract Deals', 'woocommerce' ), 'priority' => 10, 'callback' => 'woo_paym_product_tab_content' );
            return $tabs;
        } else {
        return $tabs;
        }
    }
}

function woo_paym_product_tab_content() {
    // The new tab content
    woocommerce_template_single_add_to_cart();
} 

如何根据“分组产品”>“子产品”属性隐藏此选项卡。如果子产品包含属性“PAYM”,我只希望此选项卡显示在分组产品页面上。

目前该标签设置为仅显示“分组”产品。我还想将其更改为“分组”产品和某些类别。

【问题讨论】:

  • 第二点,这行得通吗? if( $product->is_type( 'grouped' ) && $product->is_category('your_category'))
  • 实际上,首先你应该能够测试$product->get_attribute( 'PAYM' ); 但我没有使用 wooCommerce 太久了,所以我没有信心将其发布为答案跨度>
  • @JohnCH(回复第一条评论)当我尝试不显示任何选项卡时甚至不显示它破坏网站的页脚时不起作用??
  • @JohnCH(回复第二条评论)该属性仅在子产品中可见。 PAYM 仅适用于该组的子代,而不适用于该组本身。虽然我不能 100% 确定天气,但它也会获取子产品的属性,你怎么看?
  • 我不知道第一个,它会给你一个错误信息吗?对于第二个你可能需要做一个$product->get_children() 然后在孩子上使用get_attribute('PAYM')

标签: php wordpress woocommerce


【解决方案1】:

以下功能将帮助您隐藏其他产品类型的标签。

// Show custom fields for grouped product.

function hide_custom_js() {

if ( 'product' != get_post_type() ) :
    return;
endif;

?><script type='text/javascript'>
    jQuery( document ).ready( function() {
        jQuery( '.your_custom _tab_class' ).addClass( 'show_if_grouped' ).show();
    });
</script><?php
}
add_action( 'admin_footer', 'hide_custom_js' );

您必须将 .your_custom _tab_class 类替换为您的自定义选项卡类。

【讨论】:

    猜你喜欢
    • 2021-07-24
    • 2018-09-08
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    相关资源
    最近更新 更多