WordPress.org

Forums

WooCommerce - excelling eCommerce
Changing item meta after compeleted sale (2 posts)

  1. Lakjin
    Member
    Posted 1 year ago #

    Hi,

    We want to be able to add a license code as an item meta after sale is complete. We currently have working code that does this but the issue is, it assigns a license to canceled/failed sales also instead of just completed sales. Can anyone provide tips as to how to fix up the code so that item meta is only updated and license code only assigned to completed sales?

    Currently, this is the code that is being used:

    add_action('woocommerce_add_order_item_meta', array($this, 'action_woocommerce_add_order_item_meta'), 10, 2);
    
    	public function action_woocommerce_add_order_item_meta ($item_id, $values)
    	{
    		//print_r($the_order);die();
    		//iterate over all order items and assign a licence code
    		//print_r($values);
    		$licence = $this->_getProductLicenseCode((int)$values['product_id']);
    		if( !$licence )
    		{
    			return false;
    			//wp_die('Error getting product licence code');
    		}
    		woocommerce_add_order_item_meta($item_id, 'attribute_licence_code', $licence->licence_code);
    		//change licence status
    		$this->_setLicenceCodeStatus($licence->licence_id, 'assigned');
    	}

    There is obviously more code involved than this, but this is the portion I was able to identify that fires the code assigning.

    Help, please?

    http://wordpress.org/plugins/woocommerce/

  2. Lakjin
    Member
    Posted 1 year ago #

    By the way, I think the solution to this may be using a different hook. However, I've tried multiple hooks like woocommerce_order_status_completed and woocommerce_checkout_update_order_meta and woocommerce_checkout_order_processed but they don't work. Maybe I'm doing it wrong?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic