Woocommerce变体选择不起作用

时间:2018-09-04 17:37:04

标签: php wordpress woocommerce

因此,我有一个变体部分,客户可以在其中选择产品的变体。尽管该变体下拉菜单不起作用,但sku却没有变化,并且当添加到购物车中时也没有显示该变体。

变体代码如预期那样位于variable.php中。我已经尝试过修改它,但是问题仍然存在。

无论如何,这是代码:

  <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( 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 esc_html_e( 'This product is currently out of stock and unavailable.', 'exzo' ); ?></p>
    <?php else : ?>
        <?php

        foreach ( $attributes as $attribute_name => $options ) :
            $color = false;


            $terms = get_the_terms( get_the_ID(), sanitize_title( $attribute_name ) );

            ?>

            <?php
            $arr_color = null;
            foreach ( $terms as $term ) {
                $term_id = $term->term_id;

                $thumbnail_id = get_woocommerce_term_meta( $term_id, '', 'phoen_color', true );

                if ( isset( $thumbnail_id[sanitize_title( $attribute_name ) . '_thumbnail_id_phoen_color'][0] ) ) {
                    if ( isset( $thumbnail_id[sanitize_title( $attribute_name ) . '_thumbnail_id_phoen_color'][0]{1} ) ) {
                        $color = true;
                    }
                    $arr_color[] = array(
                        'slug' => $term->slug,
                        'color_hex' => $thumbnail_id[sanitize_title( $attribute_name ) . '_thumbnail_id_phoen_color'][0]
                    )
                    ?>

                    <?php
                }
            }


            ?>
<?php if ( $color != true ) : ?>
                    <div class="row col-xs-b40">
                        <div class="col-sm-3">
                            <div
                                    class="h6 detail-data-title size-1"><?php echo wc_attribute_label( $attribute_name ) . ':'; ?></div>
                        </div>
                        <div class="col-sm-9">
                            <?php
                            ob_start();
                            $selected = isset( $_REQUEST['attribute_' . sanitize_title( $attribute_name )] ) ? wc_clean( urldecode( $_REQUEST['attribute_' . sanitize_title( $attribute_name )] ) ) : $product->get_variation_default_attribute( $attribute_name );
                            wc_dropdown_variation_attribute_options( array(
                                'options' => $options,
                                'attribute' => $attribute_name,
                                'product' => $product,
                                'selected' => $selected,
                                'class' => 'SlectBox'
                            ) );
                            ?>
                            <?php

                            echo  str_replace( '"" ',  ' " ',  ob_get_clean() );
                            ?>
                    </div>
                    </div>

已经尝试将最后一部分修改为:

  <?php  $output = '<div class="product-variations-dropdown">
    <select id="available-variations" class="" name="available_variations">';

$output .= '<option value="">'. __('Choose a variation') .'</option>';

foreach( $available_variations as $variation ){
    $option_value = array();

    foreach( $variation['attributes'] as $attribute => $term_slug ){
        $taxonomy = str_replace( 'attribute_', '', $attribute );
        $attribute_name = get_taxonomy( $taxonomy )->labels->singular_name; // Attribute name
        $term_name = get_term_by( 'slug', $term_slug, $taxonomy )->name; // Attribute value term name

        $option_value[] = $attribute_name . ': '.$term_name;
    }
    $option_value = implode( ' | ', $option_value );

    $output .= '<option value="'.$variation['variation_id'].'">'.$option_value.'</option>';

}
$output .= '
    </select>
</div>';

echo $output;?>

因此,基本上,应该选择一个不同的变体来更新variation_id值,尽管它没有任何作用。有什么方法可以更改下拉菜单来更新variation_id值?

链接:https://biokimica.eu/produto/bio-k1-lava-tudo/

0 个答案:

没有答案