Top WooCommerce & WordPress Plugins › Forums › Custom Emails for WooCommerce › Get some data from Custom Product Option for Woo
- Support forum for the Custom Emails for WooCommerce.
- This topic has 2 replies, 3 voices, and was last updated 2 months, 2 weeks ago by
Tom Anbinder.
- AuthorPosts
-
July 5, 2023 at 2:57 pm #119714
art
ParticipantHi, we want to set a second custom email to display only some of the data that the user filled on a form created from the plugin “custom product options”, we get below function and how do display on email this 3 data? Thanks
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $item_data = apply_filters( 'woocommerce_get_item_data', [], $cart_item ); foreach($item_data as $key => $data) { if($data['name']=='radio-group-1662572212029' || $data['name']=='text-1662572721887' || $data['name']=='date-1662573909693') { echo $data['key']." - ".$data['value']."<br>"; } } }
- This topic was modified 3 months ago by
art.
- This topic was modified 2 months, 3 weeks ago by
WPFactory Support.
- This topic was modified 2 months, 3 weeks ago by
WPFactory Support.
July 10, 2023 at 9:55 am #119895Hi there,
Thanks for reaching out.
I have escalated this with our development team. They will get back to you as soon as they can.
Kind regards,
MoshtafizurJuly 18, 2023 at 4:17 pm #120367Hi,
Sorry for not getting back to you sooner.
You can create your own shortcodes and then use them in the custom email’s “Email content” option. For example, this PHP snippet will create the
[my_alg_wc_custom_emails_order_items_data]
shortcode:add_shortcode( 'my_alg_wc_custom_emails_order_items_data', function ( $atts, $content = '' ) { $result = ''; if ( function_exists( 'alg_wc_custom_emails' ) && ! empty( alg_wc_custom_emails()->core->shortcodes->order ) ) { $order = alg_wc_custom_emails()->core->shortcodes->order; foreach ( $order->get_items() as $item ) { foreach ( $item->get_data() as $key => $value ) { if ( in_array( $key, array( 'radio-group-1662572212029', 'text-1662572721887', 'date-1662573909693' ) ) ) { $result .= $key . ' - ' . $value . '<br>'; } } } } return $result; } );
Please note that in your snippet, you are displaying cart item data, while in my snippet, we are displaying order item data – when sending an email, we don’t have cart data already. I’m not completely sure if the
woocommerce_get_item_data
filter returns the same result as the$item->get_data()
function, but please give it a try. - This topic was modified 3 months ago by
- AuthorPosts
- You must be logged in to reply to this topic.