[+] Add a note to Orders generated by Forms Commerce linking back to the post being paid for

When using Toolset Forms Commerce to charge to publish posts a WC order is created, but when editing the order it is not possible to see what post it refers to.

This code will add a private note to the order with a link to the back-end edit page of the relevant post:

/**
 * Add a private note to Orders linking to the post which the order is to pay for
 */
add_filter( 'cred_commerce_after_send_notifications', 'ts_order_update' );
function ts_order_update( $data ){

    $order = wc_get_order( $data['order_id'] );

    $linked_postid = $data['cred_meta'][0]['cred_post_id'];
    $linked_post = get_post( $linked_postid );
    $link = get_edit_post_link( $linked_postid );

    $note = "This order relates to this post: $linked_post->post_title";

    $order->add_order_note( $note );
}

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments