Tim Brocklehurst
asked on
How to customise checkout order confirmation with variable products WooCommerce
We have variable products in our Woocommerce store. We want all variables to show (as per default) except when the user selects the 'Standard' - or in this case - 'None' variation.
We have managed to fix it how we want it in the basket and in the order emails, but we are asking for help to fix it on the Checkout page.
This is what that portion of the page looks like currently. The variation with a red arrow "Selected Custom Conjugation: None" is the one we want to exclude. We only want to see this line when any of the other options are chosen...
In the basket we were able to do it using the following JS for that page:
We were also able to do it for emails, by placing a /woocommerce/emails folder in our theme folder and adding the woocommerce email-order-items.php file with an adjustment to the conditional for displaying variations as follows:
So now, to remove it from the Checkout page, the JS option doesn't work, and I can't find the conditional in the file the same way as we could with the email php file. I have however narrowed it down to the /templates/checkout/review -order.php - line 43:
Can anyone tell me how to adjust it (or its functions - allowing for Woocommmerce updates) so that the 'None' variation is removed from the checkout page? - in case it helps, the None variation has the slug 'st'
Many thanks in advance
Tim
We have managed to fix it how we want it in the basket and in the order emails, but we are asking for help to fix it on the Checkout page.
This is what that portion of the page looks like currently. The variation with a red arrow "Selected Custom Conjugation: None" is the one we want to exclude. We only want to see this line when any of the other options are chosen...
In the basket we were able to do it using the following JS for that page:
<script>
jQuery(function($) {
var dd = $(".product-name dd.variation-Selectedcustomconjugationoption:contains('None')").hide();
dd.prev().hide();
});
</script>
And it produces this result (notice no 'None' variation showing:We were also able to do it for emails, by placing a /woocommerce/emails folder in our theme folder and adding the woocommerce email-order-items.php file with an adjustment to the conditional for displaying variations as follows:
// Variation
if ( ! empty( $item_meta->meta ) && $item_meta->meta['pa_variation'][0]!=='st' ){
echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
}
// && $item_meta->meta['pa_variation'][0]!=='st' ) - to hide 'None' variation
See this thread for background with that.So now, to remove it from the Checkout page, the JS option doesn't work, and I can't find the conditional in the file the same way as we could with the email php file. I have however narrowed it down to the /templates/checkout/review
<?php echo WC()->cart->get_item_data( $cart_item ); ?>
That's where the line pointed to with the green and red arrows, in the image above, gets delivered. Can anyone tell me how to adjust it (or its functions - allowing for Woocommmerce updates) so that the 'None' variation is removed from the checkout page? - in case it helps, the None variation has the slug 'st'
Many thanks in advance
Tim
ASKER
Ah hello again Hielo - very glad to see you on this thread!
I added that line of code, but the output was exactly that line of code - like this:
The context of the php where I entered it (with it in) looks like this - so you can see it is used within the html of the table. - (can you see where I entered your line?
I added that line of code, but the output was exactly that line of code - like this:
The context of the php where I entered it (with it in) looks like this - so you can see it is used within the html of the table. - (can you see where I entered your line?
<tbody>
<?php
do_action( 'woocommerce_review_order_before_cart_contents' );
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
<td class="product-name">
<?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . ' '; ?>
<?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '× %s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); ?>
<?php echo WC()->cart->get_item_data( $cart_item ); ?>
echo __LINE__, var_export($cart_item,true);
</td>
<td class="product-total">
<?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); ?>
</td>
</tr>
<?php
}
}
do_action( 'woocommerce_review_order_after_cart_contents' );
?>
</tbody>
That is php code, so it needs to be within php tags:
<?php
echo WC()->cart->get_item_data( $cart_item );
echo __LINE__, var_export($cart_item,true);
?>
ASKER
Ah - silly me...
OK so now I get the output of variables, in a long string... including this:
44array ( 'product_id' => 19572, 'variation_id' => 19577, 'variation' => array ( 'attribute_pa_variation' => 'st', ), 'quantity' => 1, 'line_total' => 200, 'line_tax' => 40, 'line_subtotal' => 200, 'line_subtotal_tax' => 40, 'line_tax_data' => array ( 'total' => array ( 1 => 40, ), 'subtotal' => array ( 1 => 40, ), ), 'data' => WC_Product_Variation::__se t_state(ar ray( 'variation_id' => 19577,
So can you tell me what code I should enter to hide the variation if the attribute_pa_variation = 'st' ?
OK so now I get the output of variables, in a long string... including this:
44array ( 'product_id' => 19572, 'variation_id' => 19577, 'variation' => array ( 'attribute_pa_variation' => 'st', ), 'quantity' => 1, 'line_total' => 200, 'line_tax' => 40, 'line_subtotal' => 200, 'line_subtotal_tax' => 40, 'line_tax_data' => array ( 'total' => array ( 1 => 40, ), 'subtotal' => array ( 1 => 40, ), ), 'data' => WC_Product_Variation::__se
So can you tell me what code I should enter to hide the variation if the attribute_pa_variation = 'st' ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes - that's precisely it.
Worked perfectly.
Thanks again Hielo!
T
Worked perfectly.
Thanks again Hielo!
T
Open in new window
like you did on the other thread to verify that $cart_item has:
Open in new window
when 'None' is displayed. You can then put a conditional so that the statement you posted above get executed only when 'st' is not present.