woocommerce-隐藏特定类别中的特定变化

woocommerce-隐藏特定类别中的特定变化,woocommerce,display,variations,Woocommerce,Display,Variations,我的产品分为两类: -第一个价格相同(像简单的产品):“经销商”(自动售货机) -另一个是有3种变体(S、M、XL)的“一个经营者”(商店) 有些产品在自动售货机和商店里。但是价格或尺寸是不同的 例如“我的披萨X”: -自动售货机中:M码仅9码$ -店内:S码6美元,M码8美元,XL码17美元$ 因此,在我的产品页面中,如果当前类别是自动售货机,我希望只显示“9$的尺码M”,并隐藏其他变体 或者,如果当前类别为商店,则显示商店变型(S、M、XL),并隐藏“9美元变型时的尺寸M” 我使用WC变体单

我的产品分为两类: -第一个价格相同(像简单的产品):“经销商”(自动售货机) -另一个是有3种变体(S、M、XL)的“一个经营者”(商店)

有些产品在自动售货机和商店里。但是价格或尺寸是不同的

例如“我的披萨X”: -自动售货机中:M码仅9码$ -店内:S码6美元,M码8美元,XL码17美元$

因此,在我的产品页面中,如果当前类别是自动售货机,我希望只显示“9$的尺码M”,并隐藏其他变体 或者,如果当前类别为商店,则显示商店变型(S、M、XL),并隐藏“9美元变型时的尺寸M”

我使用WC变体单选按钮来显示它们(所以是复选框而不是选项选择)

我尝试使用顶级产品类别创建如下css规则:

    <?php
/**
 * Variable product add to cart
 *
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.5.0
 *
 * Modified to use radio buttons instead of dropdowns
 * @author 8manos
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

global $product;

$attribute_keys = array_keys( $attributes );



do_action( 'woocommerce_before_add_to_cart_form' ); 


$cat = get_the_terms( $product->ID, 'product_cat' );

foreach ($cat as $topcat) {
    if($topcat->parent == 0){
      $slugTop = $topcat->slug;
    }
}



 ?>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ) ?>">
    <?php do_action( 'woocommerce_before_variations_form' ); ?>

    <?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
        <p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
    <?php else : ?>
        <table class="variations" cellspacing="0">
            <tbody>
                <?php foreach ( $attributes as $name => $options ) : ?>
                    <tr class="attribute-<?php echo sanitize_title($name); ?>">
                        <td class="label"><label for="<?php echo sanitize_title( $name ); ?>"><?php echo wc_attribute_label( $name ); ?></label></td>
                        <?php
                        $sanitized_name = sanitize_title( $name );
                        if ( isset( $_REQUEST[ 'attribute_' . $sanitized_name ] ) ) {
                            $checked_value = $_REQUEST[ 'attribute_' . $sanitized_name ];
                        } elseif ( isset( $selected_attributes[ $sanitized_name ] ) ) {
                            $checked_value = $selected_attributes[ $sanitized_name ];
                        } else {
                            $checked_value = '';
                        }
                        ?>
                        <td class="value <?php echo $slugTop; ?>">
                            <?php
                            if ( ! empty( $options ) ) {
                                if ( taxonomy_exists( $name ) ) {
                                    // Get terms if this is a taxonomy - ordered. We need the names too.
                                    $terms = wc_get_product_terms( $product->get_id(), $name, array( 'fields' => 'all' ) );

                                    foreach ( $terms as $term ) {
                                        if ( ! in_array( $term->slug, $options ) ) {
                                            continue;
                                        }
                                        print_attribute_radio( $checked_value, $term->slug, $term->name, $sanitized_name );
                                    }
                                } else {
                                    foreach ( $options as $option ) {
                                        print_attribute_radio( $checked_value, $option, $option, $sanitized_name );
                                    }
                                }
                            }

                            echo end( $attribute_keys ) === $name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
                            ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>

        <div class="single_variation_wrap">
            <?php
                do_action( 'woocommerce_before_single_variation' );
                do_action( 'woocommerce_single_variation' );
                do_action( 'woocommerce_after_single_variation' );
            ?>
        </div>

        <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
    <?php endif; ?>

    <?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>

<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
但它仍在显示


有人知道如何编辑我的代码以使其正常工作?

我只是用整个代码编辑我的帖子。实际上有“分销商”这一类:它是一台自动售货机。我的客户以特定的价格将比萨饼按特定的尺寸进行焊接,但他在他的店里以不同的价格和尺寸焊接相同的产品(“a-emporter”slug)。例如:在自动售货机中:尺码M为9$在商店中:尺码S为6$,尺码M为8$,尺码XL为16$,因此我希望在产品显示屏上显示自动售货机价格或商店价格/变化,具体取决于类别。我仅通过messenger与您联系:),因此您最好删除此问题,因为这是不可能的。
td.value.produits-a-emporter div:last-child{
            display:none !important;
        }
td.value.distributeur div:first-child, td.value.distributeur div:nth-child(2), td.value.distributeur div:nth-child(3){
            display:none !important;
        }