• Resolved sbassah

    (@sbassah)


    The Product Add-ons field doesn’t show when a table is used to display Variation options. It works okay when a normal drop-down is used for variations but doesn’t show with Variation table. Is there a way around this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author acowebs

    (@acowebs)

    Hi,
    Are you using any plugins for showing variation table, if, please share the details

    Thread Starter sbassah

    (@sbassah)

    Actually both. I first added some codes to the function file but the addons wasn’t displaying. I then tried two plugins ie. Woo Variation table and Ni WooCommerce Product Variation.

    However, below is the code I used to display the table. What am I doing wrong, please?

    
    function woocommerce_variable_add_to_cart() {
    		global $product;
    
    		$variations = $product->get_available_variations();
    		foreach ($variations as $key => $value) {
    		?>
    		<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
    			<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
    			
    			<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
    		<input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
    			<?php
    			if(!empty($value['attributes'])){
    				foreach ($value['attributes'] as $attr_key => $attr_value) {
    				?>
    				<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
    				<?php
    				}
    			}
    			?>
    			<table>
    				<tbody>
    					<tr>
    						<td>
    							
    								
    									<?php foreach ($value['attributes'] as $attrKey => $attr) :
    	$tax = str_replace('attribute_', '', $attrKey);
    	$term_obj = get_term_by('slug', $attr, $tax); ?>
    
    	<td style="width: 40%; float: left;"><b> <?php echo $term_obj->name; ?></b></td>
    
    	<?php endforeach; ?>
    						</td >
    						<td style="width: 30%; float: left;">
    							<?php echo $value['price_html'];?>
    						
    						</td>
    						<td style="width: 30%;float: right;">
    							<button type="submit" class="single_add_to_cart_button button alt"><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></button>
    						</td>
    					</tr>
    				</tbody>
    			</table>
    		</form>
    		<?php
    		}
    }
    Plugin Author acowebs

    (@acowebs)

    Hi,

    actually the form is loading at the hook woocommerce_before_add_to_cart_button
    This action hook is missing in your code.

    You can add do_action( 'woocommerce_before_add_to_cart_button' ); where the form should be loaded

    • This reply was modified 6 years, 4 months ago by acowebs.
    Thread Starter sbassah

    (@sbassah)

    Hi,

    Thanks for the prompt response. I will try it and update you, of the outcome.

    • This reply was modified 6 years, 4 months ago by sbassah.
    Thread Starter sbassah

    (@sbassah)

    You’ve been of great help so far. The addon form is now displays , after adding the do_action( 'woocommerce_before_add_to_cart_button' ); into my code. However, it pops up a required field error, even though I enter an input the text box and because of that, it doesn’t add to cart. What am I doing wrong, please? Thanks

    Thread Starter sbassah

    (@sbassah)

    Okay, I fixed it. The do_action hook was outside the form tag. It’s working now that it’s in the form tag. Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Product Addons doesn’t display with Variation table’ is closed to new replies.