I'm to go check if a product added to cart and purchased is in an order. I.e when a user purchase a variable product along with other variable products, i want to check if a specific variable product is added and purchased. So that i can dynamically show some information on the Thankyou Page and email sent to both the admin and customer.
I have tried to use "Checking that a specific attribute value is used in a cart Item (product variation)" answer code, but this doesn't work on Thankyou page once the product is purchased.
What I am trying is to display a dynamic content if products in the order has an attribute value of "Custom", as well as display an additional table row to the order table if there is a product in the order having the attribute value "order", with the following code:
function add_custom_row_to_order_table( $total_rows, $myorder_obj ) {
if ( is_attr_in_cart('custom') ) {
$cmeasuement = __( 'Yes', 'domain' );
}else{
$cmeasuement = __( 'No', 'domain' );
}
$total_rows['el_custom'] = array(
'label' => __('Custom Required?', 'domain'),
'value' => $cmeasuement,
);
return $total_rows;
}
add_filter( 'woocommerce_get_order_item_totals', 'add_custom_row_to_order_table', 10, 2 );
But I keep Getting "No" (see the screenshot below) and the reason is because the is_attr_in_cart('custom')
function is not detecting if the attribute is in the order. Help in the right direction to getting it to detect if an order has a product with specific attribute value.
Any help is appreciated.