Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Created February 13, 2017 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allysonsouza/56c55cf6087d47b5b07d4c6114546401 to your computer and use it in GitHub Desktop.
Save allysonsouza/56c55cf6087d47b5b07d4c6114546401 to your computer and use it in GitHub Desktop.
Example of custom registration add to cart template, displaying registrations details in a table.
<?php
/**
* Registration product add to cart
* Put this file in your theme under woocommerce/single-produt/add-to-cart
*
* @author Allyson Souza
* @package Registrations for WooCommerce/Templates
* @version 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
$attribute_keys = array_keys( $attributes );
do_action( 'woocommerce_before_add_to_cart_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="registrations table table-striped table-hover table-bordered table-responsive-vertical" cellspacing="0">
<thead>
<tr>
<td>
<?php _e( 'Class', 'my-text-domain' ); ?>
</td>
<td>
<?php _e( 'Day of Week', 'my-text-domain' ); ?>
</td>
<td>
<?php _e( 'Dates', 'my-text-domain' ); ?>
</td>
<td>
<?php _e( 'Schedule', 'my-text-domain' ); ?>
</td>
<td>
<?php _e( 'Available Seats', 'my-text-domain' ); ?>
</td>
<td>
<?php _e( 'Choose the quantity', 'my-text-domain' ); ?>
</td>
</tr>
</thead>
<tbody>
<?php do_action( 'woocommerce_before_variations_form' );
$count = 0;
?>
<?php foreach ( $attributes as $attribute_name => $options ) :
foreach ( $options as $option ) : ?>
<form class="registrations_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 ) ) ?>">
<tr>
<td data-label="Class" class="registration-id">
<?php echo $available_variations[ $count ]['variation_id'] ; ?>
</td>
<td data-label="Days of Week" class="registration_week-days">
<?php $product->registration_days_of_week( $available_variations[ $count ]['variation_id'] ); ?>
</td>
<td data-label="Dates" class="registration_date">
<?php $product->registration_date( $available_variations[ $count ]['variation_id'], 'd \d\e F \d\e Y' ); ?>
</td>
<td data-label="Schedule" class="registration_schedule">
<?php $product->registration_schedule( $available_variations[ $count ]['variation_id'] ); ?>
</td>
<td data-label="Available Seats" class="registration_availability">
<?php echo $available_variations[ $count ]['max_qty']; ?>
</td>
<td class="register" data-label="Choose the quantity">
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_variation"></div>
<div class="variations_button">
<span class="quantity input-group">
<input step="1" name="quantity" value="1" title="Qtd" class="input-text qty text form-control" size="4" type="number" min="1" max="<?php echo esc_attr( $available_variations[ $count ]['max_qty'] ); ?>">
<span class="input-group-btn">
<button type="submit" class="single_add_to_cart_button btn btn-action btn-success alt"><?php _e( 'Inscreva-se', 'abelman' ); ?></button>
</span>
</span>
<input name="add-to-cart" value="<?php echo absint( $product->id ); ?>" type="hidden">
<input name="product_id" value="<?php echo absint( $product->id ); ?>" type="hidden">
<input name="variation_id" class="variation_id" value="<?php echo $available_variations[ $count ]['variation_id']; ?>" type="hidden">
</div>
<input type="hidden" value="<?php echo esc_attr( $option ); ?>" id="<?php echo sanitize_title( $attribute_name ); ?>" class="" name="<?php echo 'attribute_' . sanitize_title( $attribute_name ); ?>" data-attribute_name="<?php echo 'attribute_' . sanitize_title( $attribute_name ); ?>">
</td>
</tr>
<?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>
<?php
$count++;
endforeach;?>
<?php endforeach;?>
</tbody>
</table>
<?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_add_to_cart_form' ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment