Get some data from Custom Product Option for Woo

Top WooCommerce & WordPress Plugins Forums Custom Emails for WooCommerce Get some data from Custom Product Option for Woo

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #119714
    art
    Participant

    Hi, 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 9 months, 3 weeks ago by art.
    • This topic was modified 9 months, 3 weeks ago by WPFactory Support.
    • This topic was modified 9 months, 3 weeks ago by WPFactory Support.
    #119895
    Moshtafizur
    Moderator
    Plugin Support

    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 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.