• Hello, I have been using the plugin for completing orders once a day if the postal cards have been made.

    After while I noticed that as the setting the status of order to complete fires also the order complete email, the customers was requesting postal tracking codes, as it seems when “Order Status Rules for WooCommerce” changes the order status to completed some hooks is not fired. For example following hooks is not fired woocommerce_email_order_meta on completation email.

    Also noted the when user manually closes the order the comment is rated note and when plugin does it its system-note. Please attached image bellow.

    https://imgur.com/a/aQQOp21

    • This topic was modified 4 months, 3 weeks ago by simppa999.
    • This topic was modified 4 months, 3 weeks ago by simppa999.
    • This topic was modified 4 months, 3 weeks ago by simppa999.
    • This topic was modified 4 months, 3 weeks ago by simppa999.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi @simppa999,

    Thanks for reaching out.

    I have escalated this with our development team. They will get back to you as soon as possible.

    Kind regards.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @simppa999,

    Our plugin calls the standard WooCommerce update_status() function, which fires all related hooks, so I believe that the woocommerce_email_order_meta hook you mentioned is also fired.

    However, this hook has only one callback – order_meta() function – and it depends on the woocommerce_email_order_meta_fields filter (or its deprecated version – woocommerce_email_order_meta_keys). By default in WooCommerce, this filter doesn’t have any callbacks attached, i.e., there should be some custom code that adds fields there, otherwise nothing is added to the email. Do you know which plugin or custom code deals with the woocommerce_email_order_meta action, or woocommerce_email_order_meta_fields (or woocommerce_email_order_meta_keys) filter on your site? If so, could you please post the code?

    Thread Starter simppa999

    (@simppa999)

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @simppa999,

    I’ve checked your links, and I think I know why the meta is not being added. The “Posti Shipping” plugin adds the callback only in the backend (is_admin() function on the line 192 in the posti-shipping/core/class-core.php file), and when our rules are processed by the cron job, the is_admin() function returns false. To be sure, could you please try running our rules manually via the “Run all rules now” tool (in “WooCommerce > Settings > Order Status Rules > Tools”)? I think the meta will be added in this case.

    Thread Starter simppa999

    (@simppa999)

    You are correct, the tracking codes are attached when running the cron manually. So the change needed to be done in “posti shipping” plugin.

    Do you have good suggestion how to include plugin hooks “$this->admin?=?$this->load_admin_class()” only for cron, and not always? Please.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @simppa999,

    Glad to hear we figured out the cause of the problem.

    Now, regarding the solution – the first thing that comes to mind – recreate our own attach_tracking_to_email() callback (from the class-admin.php file). It should look like this (I didn’t test it, though):

    add_action( 'plugins_loaded', function () {
    if ( wp_doing_cron() ) {
    add_action( 'woocommerce_email_order_meta', function ( $order, $sent_to_admin = false, $plain_text = false, $email = null ) {

    // Must be a "Completed order" email
    if ( ! isset( $email->id ) || 'customer_completed_order' !== $email->id ) {
    return;
    }

    // Get labels
    $labels = $order->get_meta( '_wc_pakettikauppa_labels' );
    if ( empty( $labels ) ) {
    return;
    }

    // Get tracking codes
    $tracking_codes = array();
    foreach ( $labels as $label ) {
    if ( ! empty( $label['tracking_code'] ) ) {
    array_push(
    $tracking_codes,
    array(
    'code' => $label['tracking_code'],
    'url' => $label['tracking_url'],
    'point' => $label['pickup_name'],
    )
    );
    }
    }
    if ( empty( $tracking_codes ) ) {
    return;
    }

    // Output
    $add_pickup_point_to_email = 'yes'; // Change this to 'no' if needed
    ?><h2><?php esc_attr_e( 'Tracking', 'woo-pakettikauppa' ); ?></h2><?php
    foreach ( $tracking_codes as $code ) {
    ?><p><?php
    if ( 'yes' === $add_pickup_point_to_email ) {
    if ( ! empty( $code['point'] ) ) {
    ?><b><?php esc_attr_e( 'Pickup point', 'woo-pakettikauppa' ); ?></b>
    <?php esc_attr( $code['point'] ); ?><br/><?php
    } else {
    ?><b><?php esc_attr_e( 'Pickup point', 'woo-pakettikauppa' ); ?> :</b> —<br/><?php
    }
    }
    echo sprintf(
    __( 'You can %1$s with tracking code %2$s.', 'woo-pakettikauppa' ),
    '<a href="' . esc_url( $code['url'] ) . '">' . __( 'track your order', 'woo-pakettikauppa' ) . '</a>',
    '<b>' . esc_attr( $code['code'] ) . '</b>'
    );
    ?></p><?php
    }

    }, 10, 4 );
    }
    } );

    Please give it a try and let me know what you think. And if you like the plugin, please consider leaving me a rating.

    Thread Starter simppa999

    (@simppa999)

    Thank you for replay. Still not working, but need to try debug more.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @simppa999,

    I’ve made some tests and I believe it should be working.

    Please try to add something simple to the email at first, e.g.:

    add_action( 'plugins_loaded', function () {
    if ( wp_doing_cron() ) {
    add_action( 'woocommerce_email_order_meta', function ( $order, $sent_to_admin = false, $plain_text = false, $email = null ) {

    echo 'TEST';

    }, 10, 4 );
    }
    } );

    If it’s working, try adding some code from the original snippet, e.g.:

    add_action( 'plugins_loaded', function () {
    if ( wp_doing_cron() ) {
    add_action( 'woocommerce_email_order_meta', function ( $order, $sent_to_admin = false, $plain_text = false, $email = null ) {

    // Must be a "Completed order" email
    if ( ! isset( $email->id ) || 'customer_completed_order' !== $email->id ) {
    return;
    }

    echo 'TEST';

    }, 10, 4 );
    }
    } );

    I hope this helps.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.