Skip to content

Instantly share code, notes, and snippets.

@hadamlenz
Created October 20, 2017 19:40
Show Gist options
  • Save hadamlenz/6ea54abbce7c8e74fea50784115d7168 to your computer and use it in GitHub Desktop.
Save hadamlenz/6ea54abbce7c8e74fea50784115d7168 to your computer and use it in GitHub Desktop.
Add a name your price product to an Event Ticket Plus Ticket group
<?php
//add this to wootickets/tickets.php
//add after the big foreach ( $tickets as $ticket )
//requires ACF to set a custom field that pulls the product you want to add with a post object field
//requires WooComerce Name Your Price plugin
if( 0 < count( get_field( 'add_products_to_tickets' ) ) ):
foreach( get_field( 'add_products_to_tickets' ) as $extra_product ):
$product = wc_get_product( $extra_product );
if( class_exists('WC_Name_Your_Price')){
$nyp = get_post_meta( $extra_product->ID, '_nyp', true);
if( 'yes' === $nyp){
?>
<tr class="woocomerce" data-product-id="<?php echo $extra_product->ID ?>">
<td>
<input type="hidden" name="quantity_<?php echo $extra_product->ID ?>" value="1" title="Qty" class="qty">
</td>
<td><?php echo $product->name ?></td>
<td>
<span class="woocommerce-Price-amount amount">
<?php echo WC_Name_Your_Price_Helpers::get_price_input( $extra_product->ID, $prefix ); ?>
</span>
</td>
<td>
<?php echo $product->post->post_excerpt ?>
</td>
</tr>
<input type="hidden" name="product_id[]" value="<?php echo $extra_product->ID ?>">
<?php
} else {
//add more products here
}
}
endforeach; endif; ?>
@hp7
Copy link

hp7 commented Feb 14, 2018

Tried but get a
Warning: Invalid argument supplied for foreach() in /*****/tribe-events/wootickets/tickets.php on line 210
Line in question is
foreach( get_field( 'add_products_to_tickets' ) as $extra_product ):
Can you give a little more direction on the ACF config and exactly where and how to add this to WP 4.9.4 - events tickets plus / views
This would be a great solution for many people until MTribe adds this feature or supports NYP for WooCommerce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment