• Resolved Jan

    (@krugmedien)


    Hi,
    I want woocommerce to send an email to a customer, if the download limit in his order changes. (For example if the customer used all his downloads and I set it back to “2”.)
    Is there a php hook or filter that is triggered if the limit changes?
    Thank you very much.
    Jan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Before moving forward, can you provide us with more details, please? Is the site using any plugin to manage order download limits?

    We can get a better idea by checking the system status report on your site. Can you please share a copy of your site’s System Status Report? You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support”.?

    Thread Starter Jan

    (@krugmedien)

    Possible Solution:

    function mail_to_customer_on_downloads_remaining_change ( $post_id, $post_data )
    {
    
        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || $post_data["post_type"] != "shop_order" )
        {
            return;
        }
    
        global $wpdb;
    
        $downloads_remaining_db = $wpdb->get_results( "SELECT downloads_remaining FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = $post_id", ARRAY_A );
        $downloads_remaining_post = $_POST["downloads_remaining"];
    
        for ( $i=0; $i < count($downloads_remaining_db); $i++ )
        {
    
            if ( !in_array($downloads_remaining_db[$i]["downloads_remaining"], $downloads_remaining_post) )
            {
    
                $old_text = esc_html( 'We have finished processing your order.', 'woocommerce' );
                $new_text = 'we have reset the download limits in your order. You can now download the files again:';
    
                $order = wc_get_order( $post_id );
    
                $order_id  = $order->get_id();
                $billing_email  = $order->get_billing_email();
    
                $mailer = WC()->mailer();
    
                $recipient = $billing_email;
                $subject = 'Download limits in your order #' . $order_id . ' changed';
                $content = wc_get_template_html( 'emails/customer-completed-order.php', array(
                        'order'         => $order,
                        'email_heading' => 'Order #' . $order_id,
                        'sent_to_admin' => false,
                        'plain_text'    => false,
                        'email'         => $mailer
                    ) );
                $content = str_replace( $old_text, $new_text, $content);
                $headers = "Content-Type: text/html\r\n";
    
                $mailer->send( $recipient, $subject, $content, $headers );
    
                return;
    
            }
    
        }
    
    }
    
    add_action( 'pre_post_update', 'mail_to_customer_on_downloads_remaining_change', 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Send Email To Customer When Order Download Limit Changes’ is closed to new replies.