Get some data from Custom Product Option for Woo

Forums Custom Emails for WooCommerce Get some data from Custom Product Option for Woo

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #119895
    Moshtafizur
    Participant

    Hi 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,
    Moshtafizur

    #120367
    Tom Anbinder
    Moderator
    Plugin Support

    Hi,

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.