Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have edited function send() to attach the file in woo commerce plugin when, I am use the attachment file path statically it work's but when, I put it on dynamically attachment source not able send the attachment but, I am getting mail.I am using select query for getting image from database to attach in mail.

function send( $to, $subject, $message, $headers, $attachments ) {
 global $wpdb;

             $current_post1=$post->ID; 
    $result1=$wpdb->get_results("SELECT BgImageName FROM ca_woocommerce_order_items where order_id = $current_post1 ");

     foreach ( $result1 as $print1 )  
     echo $imgemail=$print1->BgImageName;


      //static path it's work
   //$attachments = array(  '/home2/rahulr/public_html/cutting-edge/wordpress_theme/user_templates/1384010402.png' );  

     //dynamic path it's not working
   $attachments = array('/home2/rahulr/public_html/cutting-edge/wordpress_theme/user_templates/'.$imgemail);


        add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
        add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
        add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );

        wp_mail( $to, $subject, $message, $headers, $attachments );

        remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
        remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
        remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
    }
share|improve this question

1 Answer 1

I have made changes in this core file into the function send() plugins/woocommerce/classes/abstracts/abstract-wc-email.php .Here i have written the query for to get the last image which is design on canvas by user(front end).Now image attachment working perfectly for me, I think so there is no need to buy woo commerce email attachment plugin as per discussion on word press forums forum reference link

 function send( $to, $subject, $message, $headers, $attachments ) {
               global $wpdb;
      $result = $wpdb->get_results ( "SELECT * FROM user_templates  where id= ".$_SESSION['user_te']);
      foreach ( $result as $print )  
      //$finalorederimage=$print->BgImageName;
      $img_post=$print->BgImageName;

    $id = stripslashes_deep($img_post); //added stripslashes_deep which removes WP escaping.


    //$wpdb->insert('ca_woocommerce_order_items', array('BgImageName'=>$id));
     //$wpdb->update('ca_woocommerce_order_items', array('BgImageName'=>$id), array('order_id'=>$id));

    $limitorder=$wpdb->get_results("SELECT * FROM ca_woocommerce_order_items ORDER BY order_item_id DESC LIMIT 1");
       foreach ( $limitorder as $limitord )  
      $finalorederlimit=$limitord->order_item_id;


           $table = "ca_woocommerce_order_items";
            $data_array = array('BgImageName' => $id);
            $where = array('order_item_id' => $finalorederlimit);
            $wpdb->select( $table, $data_array, $where ); 
            foreach ( $data_array as $prinatrrrrrrrt ) 
    $attachments = array('/home2/rahulr/public_html/cutting-edge/wordpress_theme/user_templates/'.$prinatrrrrrrrt);
     //$attachments = array('/home2/rahulr/public_html/cutting-edge/wordpress_theme/user_templates/'. $_SESSION['img_postjjjjjjj']);


            add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
            add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
            add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );

          wp_mail( $to, $subject, $message, $headers, $attachments);



            remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
            remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
            remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
        }

I got the bellow mail attachment after execution of this code .

Here is attachment  screen shot i got

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.