On a Wordpress website,I am currently trying to setup a Woocommerce and Learnpress plugins. I Use Woocommerce Checkout Add-ons commercial plugin which allows to create some additional checkout fields.
I would like to display conditionally some checkout fields only when certain Learnpress courses are present in the checkout cart.
The code present in the checkout plugin is as follows:
<?php if ( $add_on_fields ) : ?>
<div id="wc_checkout_add_ons">
<?php
foreach ( $add_on_fields as $key => $field ) :
woocommerce_form_field( $key, $field, WC()->checkout()->get_value(
$key ) );
endforeach;
?>
</div>
<?php endif; ?>
So started going this route:
<div id="wc_checkout_add_ons">
<?php
$course_category = get_the_terms( $post->ID, 'course_category' );
echo $course_category;
if ($course_category == 'weekend-intensives') {
foreach ( $add_on_fields as $key => $field ) :
woocommerce_form_field( $key, $field, WC()->checkout()->get_value( $key ) );
endforeach;
} else {
echo ('Proceed with checkout');
}
?>
</div>
Right now I don't even get that initial echo for $course_category so I know that I am already wrong there...
I need to figure out what the code would be for getting the learnpress course category of the course in the checkout/cart.
I know there is a lot more to it than this and I am likely way off, but I am willing to work through it with some assistance.
Any help would be greatly appreciated.
WC()->cart->get_cart()to get list of products that are present in your cart, then you can write a condition that only show the checkout field if a certain product ( the learnpress related product ) is in the cart. - Amin