The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Changing item meta after compeleted sale (2 posts)

  1. Ashraf
    Posted 2 years ago #


    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)
    		//iterate over all order items and assign a licence code
    		$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?


  2. Ashraf
    Posted 2 years 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
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic