Get WooCommerce Product Attribute Image Thumbnail Programmatically with PHP View Larger Image Copy to ClipboardSyntax Highlighterfunction ax_woo_purchases() { // Get Current User $user = wp_get_current_user(); // Get all the Current User's Orders $user_orders_args = array( 'customer_id' => $user->ID ); $orders = wc_get_orders($user_orders_args); // Start the Capture for Output ob_start(); // If there are orders for this user if ( isset($orders) ) { // Iterate through each order foreach ($orders as $order){ // Get items/products inside the order, then iterate through each item/product foreach ($order->get_items() as $key => $order_line) { // Get the Order's Data $order_data = $order_line->get_data(); // Get the Product $product = wc_get_product($order_data['product_id']); // Get the Product's Attributes $product_atts = $product->get_attributes(); // Iterate through all the Attributes (Teams), finding the Team's Logo foreach ( $product_atts as $attribute ) { // Get term data from Attribute Image plugin settings $term_data = get_option( 'woocommerce_attribute_image_term_data' ); // Get thumbnail $term_id = $attribute->get_id(); $thumbnail_id = isset( $term_data[$term_id]['thumbnail'] ) ? $term_data[$term_id]['thumbnail'] : ''; $ax_thumbnail = "default-thumbnail.png"; // Assign the Thumbnail URL or use the Sports Raffle logo if ( $thumbnail_id ) { $thumbnail_src = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail', false ); $thumbnail_url = ! empty( $thumbnail_src[0] ) ? $thumbnail_src[0] : $ax_thumbnail; } else { $thumbnail_url = $ax_thumbnail; } // WooCommerce Product Attributes Images/Thumbnails printf("", $thumbnail_url, // Team Logo $attribute->get_name() // CSS Class Name for Debugging ); } // end foreach order items } // end foreach orders } // end if isset $orders // Send the Capture for the Shortcode $output = ob_get_contents(); ob_end_clean(); return $output; } add_shortcode( 'ax_my_teams' , 'ax_woo_purchases' ); By FloatingAx|2021-03-03T11:17:36-06:00October 28, 2020|Web Development|0 Comments Share This Story, Choose Your Platform! FacebookTwitterRedditLinkedInWhatsAppTumblrPinterestVkXingEmail