Emails personalizados en Woocommerce usando Chat Gpt

En muchas ocasiones necesitamos crear emails personalizados en nuestra tienda online de wordpress pero no queremos usar mas plugins.

En este video te mostraré cómo podemos hacerlo usando un código que nos ofrece chatgpt.

Este es el código que he utilizado:

add_action('woocommerce_email_after_order_table', 'custom_email_content', 10, 4);

function custom_email_content($order, $sent_to_admin, $plain_text, $email) {
    // Reemplaza 'your_product_id' con el ID del producto específico
    $target_product_id = 'your_product_id';

    // Verifica si el producto objetivo está en el pedido
    $product_found = false;

    foreach ($order->get_items() as $item) {
        if ($item->get_product_id() == $target_product_id) {
            $product_found = true;
            break;
        }
    }

    // Si el producto está en el pedido, agrega el contenido adicional
    if ($product_found) {
      echo '<p>Recuerda que este producto debe estar fuera del alcance de los niños.</p>';
        echo '<p><a style="background-color: #0073e6; color: #fff; text-decoration: none; padding: 10px 20px; border-radius: 5px;" href="http://armasparaemprender.com/guia-completa-de-suplementos-deportivos-nutricion-suplementacion-y-ganar-masa-muscular">VER INDICACIONES DE USO</a></p>';    }
}
Save & Share Cart
Your Shopping Cart will be saved and you'll be given a link. You, or anyone with the link, can use it to retrieve your Cart at any time.
Back Save & Share Cart
Your Shopping Cart will be saved with Product pictures and information, and Cart Totals. Then send it to yourself, or a friend, with a link to retrieve it at any time.
Your cart email sent successfully :)