WooCommerce在商店页面上显示下拉列表变体

时间:2018-08-06 15:04:32

标签: php wordpress woocommerce variations

我有这段代码给我错误。

<?php if( $product->is_type( 'variable' )) {

  wp_enqueue_script('wc-add-to-cart-variation');

  $attribute_keys = array_keys( $product->get_variation_attributes() );

  ?>

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

<?php if ( empty( $product->get_available_variations() ) && false !== $product->get_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 ( $product->get_variation_attributes() as $attribute_name => $options ) : ?>
      <tr>
        <td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
        <td class="value">
          <?php
            $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 ) );
          ?>
        </td>
      </tr>
      <?php endforeach;?>
    </tbody>
  </table>

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

  <div class="single_variation_wrap">
    <?php
      /**
       * woocommerce_before_single_variation Hook.
       */
      do_action( 'woocommerce_before_single_variation' );

      /**
       * woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
       * @since 2.4.0
       * @hooked woocommerce_single_variation - 10 Empty div for variation data.
       * @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
       */
      do_action( 'woocommerce_single_variation' );

      /**
       * woocommerce_after_single_variation Hook.
       */
      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 class="cart" action="<?php echo esc_url( get_permalink() ); ?>" method="post" enctype='multipart/form-data'>
  <span class="price"><?php echo $product->get_price_html(); ?></span>
  <?php
    woocommerce_quantity_input( array(
      'min_value'   => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
      'max_value'   => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
      'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(),
    ) );
  ?>
  <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>

</form>

由于文件wp-content/themes/Child-Theme/functions.php的第20行出现错误,您的PHP代码更改已回滚。请修复并尝试再次保存。

  

语法错误,意外的'<'

第20行是<?php if( $product->is_type( 'variable' )) {

如何解决?

0 个答案:

没有答案