So fügen Sie verwandte Produkte oder Cross-Sells hinzu, um E-Mails in WooCommerce zu bestellen

Lesezeit: 3 Minuten

Ich kann anscheinend keine Möglichkeit finden, verwandte Produkte oder Cross-Sells hinzuzufügen, um E-Mails in WooCommerce zu bestellen, und es tut meinem Gehirn weh. Ich bin mir sicher, dass es möglich sein muss, aber ich kann es nicht zum Laufen bringen. Ich habe versucht, do_shortcode nach der Bestelltabelle hinzuzufügen, aber das hat nicht funktioniert.

So fugen Sie verwandte Produkte oder Cross Sells hinzu um E Mails
Hetram Janghu

Sie können dies in Ihre untergeordneten Themen einfügen functions.php Datei:

// product suggestion in order mail
function order_mail_product_suggestion($atts) {
    $atts=shortcode_atts(
        array(
            'id' => '',
        ), $atts, 'order_mail_product_suggestion');
    $orderId = esc_attr($atts['id']);
    $order = wc_get_order( (int)$orderId );
    $items = $order->get_items();
    $cat = array();
    $pid = array();
    foreach ( $items as $item ) {
        $pid[] = $item->get_product_id();
        $terms = wp_get_post_terms($item->get_product_id(),'product_cat',array('fields'=>'ids'));
        foreach ( $terms as $term ) {
            $cat[] = $term;
        }
    }
    $uniuqcat = array_unique($cat);
    $uniuqpid = array_unique($pid);
    $html="";
    $args = array(
        'post_type'             => 'product',
        'stock'                 => 1,
        'post_status'           => 'publish',
        'ignore_sticky_posts'   => 1,
        'posts_per_page'        => '20',
        'tax_query'             => array(
            array(
                'taxonomy'      => 'product_cat',
                'field' => 'term_id',
                'terms'         => implode(',', $uniuqcat),
                'operator'      => 'IN'
            ),
            array(
                'taxonomy'      => 'product_visibility',
                'field'         => 'slug',
                'terms'         => 'exclude-from-catalog',
                'operator'      => 'NOT IN'
            )
        )
    );
    $loop = new WC_Product_Query($args);
    $products = $loop->get_products();
    if ($products) {
        $html .= '<div id="suggestion" style="padding: 20px 0;border-top: 1px solid #eee;">';
            $html .= '<h2 style="text-align: center;font-weight: 400;color: #000;">PLUS, MORE THINGS YOU MAY LIKE</h2>';
            $html .= '<table style="width: 100%;table-layout: fixed;border-collapse: collapse;">';
                $html .= '<tbody>';
                    $html .= '<tr>';
                            $i=0;
                            foreach ( $products as $product ) {
                                if (in_array($product->get_id(), $pid)) {
                                    continue;
                                }
                                $html .= '<td align="center" style="padding: 5px;border: 1px solid #eee;">';
                                if (has_post_thumbnail( $product->get_id() )) {
                                    $html .= get_the_post_thumbnail($product->get_id(), 'shop_catalog');
                                } else {
                                    $html .= '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />';
                                }
                                $html .= '<h3><a style="color: #000;font-weight: normal;text-decoration: none;font-size: 13px;text-align: center;display: block;line-height: 16px;" href="'.get_permalink(%20$product->get_id()%20).'">'.esc_attr($product->get_title() ? $product->get_title() : $product->get_id()).'</a></h3>';
                                $html .= '<p><a style="font-weight: normal;text-decoration: none;display: block;margin: 0 auto;max-width: 72px;padding: 4px 9px;text-align: center;background-color: #000;color: #fff;font-size: 13px;" href="'.get_permalink(%20$product->get_id()%20).'" class="shop-now">Shop Now</a></p>';
                                $i++;
                                if($i==4) break;
                            }
                    $html .= '</tr>';
                $html .= '</tbody>';
            $html .= '</table>';
        $html .= '</div>';
    }
    // now return the preapred html
    return $html;
}
// register shortcode
add_shortcode('email_product_suggestion', 'order_mail_product_suggestion');

Rufen Sie dann die Funktion in E-Mail-Vorlagen wie folgt auf: –

// Product suggestions
$order = $email->object;
if ( $order ) {
   $id = $order->get_id();
   echo do_shortcode( '[email_product_suggestion id="'.$id.'" ]' );
}

Dadurch werden Produkte aus der Kategorie angezeigt, in die der aktuelle Bestellartikel gehört, und Artikel ausgeschlossen, die bereits in der Bestellung enthalten sind.

So fugen Sie verwandte Produkte oder Cross Sells hinzu um E Mails
Hippocoder

Sie müssen dies mit PHP in der E-Mail-Vorlage tun. Sie würden email-footer.php bearbeiten und so etwas hinzufügen:

<?php

    echo do_shortcode('[related_products per_page="4"]');

?>

Sie möchten dies in die Tabelle einfügen, nicht unter die Tabelle. Fügen Sie einfach ein Extra hinzu und legen Sie es dort ein.

1004180cookie-checkSo fügen Sie verwandte Produkte oder Cross-Sells hinzu, um E-Mails in WooCommerce zu bestellen

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy