Advertisement
Guest User

variable.php

a guest
Aug 30th, 2015
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Variable product add to cart
  4.  *
  5.  * @author  WooThemes
  6.  * @package WooCommerce/Templates
  7.  * @version 2.4.0
  8.  */
  9. if ( ! defined( 'ABSPATH' ) ) {
  10.     exit;
  11. }
  12.  
  13. global $product;
  14.  
  15. $attribute_keys = array_keys( $attributes );
  16.  
  17. do_action( 'woocommerce_before_add_to_cart_form' ); ?>
  18.  
  19. <form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo esc_attr( json_encode( $available_variations ) ) ?>">
  20.     <?php do_action( 'woocommerce_before_variations_form' ); ?>
  21.  
  22.     <?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
  23.         <p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
  24.     <?php else : ?>
  25.         <table class="variations" cellspacing="0">
  26.             <tbody>
  27.                 <?php
  28.                     $variations_arr = array();
  29.                     foreach ( $attributes as $attribute_name => $options ) :
  30.                         ob_start(); ?>
  31.                         <tr>
  32.                             <td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
  33.                             <td class="value">
  34.                                 <?php $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
  35.                                 wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
  36.                                 echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : ''; ?>
  37.                             </td>
  38.                         </tr>
  39.                         <?php $variations_ob = ob_get_clean();
  40.                         $variations_arr[wc_attribute_label($attribute_name)] = $variations_ob;
  41.                     endforeach;
  42.  
  43.                     foreach ($variations_arr as $name => $ob) {
  44.                         echo str_ireplace('choose an option', 'Choose '.$name, $ob );
  45.                     } ?>
  46.                 <?php endforeach;?>
  47.             </tbody>
  48.         </table>
  49.  
  50.         <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
  51.  
  52.         <div class="single_variation_wrap" style="display:none;">
  53.             <?php
  54.                 /**
  55.                  * woocommerce_before_single_variation Hook
  56.                  */
  57.                 do_action( 'woocommerce_before_single_variation' );
  58.  
  59.                 /**
  60.                  * woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
  61.                  * @since 2.4.0
  62.                  * @hooked woocommerce_single_variation - 10 Empty div for variation data.
  63.                  * @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
  64.                  */
  65.                 do_action( 'woocommerce_single_variation' );
  66.  
  67.                 /**
  68.                  * woocommerce_after_single_variation Hook
  69.                  */
  70.                 do_action( 'woocommerce_after_single_variation' );
  71.             ?>
  72.         </div>
  73.  
  74.         <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
  75.     <?php endif; ?>
  76.  
  77.     <?php do_action( 'woocommerce_after_variations_form' ); ?>
  78. </form>
  79.  
  80. <?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement