0

我使用了 Damin Carbery 的 webhook 插件,用于在邮件模板联系表 7 中包含 Woocommerce 产品图像。

// Add product image to email as an attachment
add_filter( 'wpcf7_mail_components', 'dcwd_cf7_mail_components', 10, 3 );
function dcwd_cf7_mail_components( $components, $current_cf7_form, $form_object ) {
    $cf7_form_id = 10454;
  
    // Verify that the we are processing the correct form.
    if ( $cf7_form_id == $current_cf7_form->id() ) {
        // Ensure that a match was found.
        if ( 1 === preg_match( '/Product ID: (\d+)/m', $components[ 'body' ], $matches ) ) {
            $product_id = $matches[1];
            
            // Check that the matched product ID is a number.
            if ( ( $product_id > 0 ) && is_numeric( $product_id ) ) {
                // Create a product object...
                $product = wc_get_product( $product_id );
                // checking that the ID is a valid product...
                if ( is_object( $product ) ) {
                    // then get the product image url.
                    $product_image_url = wp_get_attachment_image_src( $product->get_image_id(), 'large' )[ 0 ];
                    if ( $product_image_url ) {
                        // Change the url to an absolute path to include it in the email.
                        $product_image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $product_image_url );
                        
                        // Verify that the file exists before appending it to the attachments array.
                        if ( file_exists( $product_image_path ) ) {
                            $components[ 'attachments' ][] = $product_image_path;
                        }
                    }
                }
            }
        }
    }

    return $components;
}

它是在邮件附件中添加产品图片的插件,但我需要在邮件正文中添加图片。我认为如果改变:

$components[ 'attachments' ][] = $product_image_path;

return $components;

为了“beforesendmail”功能并正确配置,它将在邮件正文中添加图像(到开始),例如<img src="$beforesendmail">

或第二个选项(最有可能):

我还使用 CF7 Dynamic Text Extension 在邮件模板中添加产品标题。我可以从“将产品图像添加到电子邮件”插件工作结果中写入图像链接到动态隐藏字段并在模板中使用它吗?

对不起我的英语不好..

4

0 回答 0