• Resolved Alex Musial

    (@bigaltheking)


    I am trying to attach a file to emails, and I can get it working for existing orders that i have tested.
    However, when i try to submit a new order, i get the following error:

    2019-05-21T20:10:05+00:00 CRITICAL Uncaught Error: Call to undefined method stdClass::get_status() in /home/hypitchmarketing/public_html/wp-content/themes/hypitch-onepress-child/functions.php:401
    Stack trace:
    #0 /home/hypitchmarketing/public_html/wp-includes/class-wp-hook.php(286): attach_terms_conditions_pdf_to_email(Array, ‘qwc_req_new_quo…’, Object(stdClass))
    #1 /home/hypitchmarketing/public_html/wp-includes/plugin.php(208): WP_Hook->apply_filters(Array, Array)
    #2 /home/hypitchmarketing/public_html/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php(403): apply_filters(‘woocommerce_ema…’, Array, ‘qwc_req_new_quo…’, Object(stdClass))
    #3 /home/hypitchmarketing/public_html/wp-content/plugins/quotes-for-woocommerce/includes/emails/class-qwc-req-new-quote.php(80): WC_Email->get_attachments()
    #4 /home/hypitchmarketing/public_html/wp-includes/class-wp-hook.php(286): QWC_Request_New_Quote->trigger(3860)
    #5 /home/hypitchmarketing/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)
    #6 /home/hypitchmar in /home/hypitchmarketing/public_html/wp-content/themes/hypitch-onepress-child/functions.php on line 401

    Below is the function i am using,
    and this is line 401: $order_status = $order->get_status();

    Any idea why I would get an error with “get_status()” ?

    /*
    * Attach Terms & Conditions to email, based on Category
    */

    add_filter( ‘woocommerce_email_attachments’, ‘attach_terms_conditions_pdf_to_email’, 10, 3);

    function attach_terms_conditions_pdf_to_email ( $attachments, $status , $order ) {

    $allowed_post_statuses = array (‘Approved’, ‘completed’); // STATUS TO ADD THE TERMS TO
    $order_status = $order->get_status();
    if ($order_status == null) {

    }
    else {
    if( isset( $status ) && in_array ( $order_status, $allowed_post_statuses ) ) { //check if status is on status list

    $send_email = false; // set email to false
    $order_items = $order->get_items(); //get order items

    foreach ($order_items as $item) { // loop through order items
    $terms = wp_get_post_terms( $item->get_product_id(), ‘product_cat’ );
    // Loop through the product categories WP_Term objects
    foreach( $terms as $wp_term ){
    // Get the product category ID
    $term_id = $wp_term->term_id;

    switch($term_id) {
    case 70:
    $your_pdf_path = WP_CONTENT_DIR . ‘/uploads/test.pdf’;
    $attachments[] = $your_pdf_path;
    break;
    case 74:
    $your_pdf_path = WP_CONTENT_DIR . ‘/uploads/test1.pdf’;
    $attachments[] = $your_pdf_path;
    break;
    }

    }
    }
    }
    }
    return $attachments;
    }

    Thanks

    Alex

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Attach file to email’ is closed to new replies.