BuddyDev

Search

Buddyblog pay per post – how to delete pending oreders when draft is deleted

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #50807

    Hello Ravi,

    I have added the processing and on-hold but the code did not empty the cart when the unpaid (pending) post was deleted. I aslo tried both empty cart and delete order together with code below

    
     function empty_cart_and_delete_order_on_pending_post_deletion( $post_id ) {
        $post = get_post($post_id);
    
        if ( ! $post ) {
            return;
        }
    
        if ($post->post_status === 'pending' && $post->post_type === 'post') {
            if (function_exists('bbl_ppp_get_post_order_id') && function_exists('wc_get_order')) {
                $order_id = bbl_ppp_get_post_order_id($post_id);
    
                if ($order_id) {
                    $order = wc_get_order($order_id);
    
                    if ($order && in_array($order->get_status(), array('processing', 'on-hold', 'pending', 'draft'))) {
                        // Empty the cart
                        WC()->cart->empty_cart(true);
    					
    		    // Delete the pending order
                        $order->delete_order(true);
                    }
                }
            }
        }
    }
    add_action('before_delete_post', 'empty_cart_and_delete_order_on_pending_post_deletion'); 
    

    This also did not work

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #50812

    Hello Tosin,

    Thank you for the acknowledgement. I will check and let you know.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved