WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
How do I add a unique value to the $values string in woocommerce? (1 post)

  1. TimoVeld
    Member
    Posted 1 year ago #

    Hi all.
    So I finally found out how to edit custom data to an order in the database.

    I'm using the following code in class-wc-checkout.php:
    woocommerce_add_order_item_meta( $item_id, '_test_db_write', $values['timestamp'] );

    To get the value "timestamp" from my $values array and put it in the database.

    For testing purposes I'm trying to add a timestamp, because I want this value to be unique for each order_item_id.

    timestamp is put in the array in class-wc-cart.php:

    if ( isset( $woocommerce->session->cart ) && is_array( $woocommerce->session->cart ) ) {
    				$cart = $woocommerce->session->cart;
    
    				foreach ( $cart as $key => $values ) {
    
    					$_product = get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
    
    					if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > 0 ) {
    
     $this->cart_contents[ $key ] = apply_filters( 'woocommerce_get_cart_item_from_session', array(
    							'product_id'	=> $values['product_id'],
    							'variation_id'	=> $values['variation_id'],
    							'variation' 	=> $values['variation'],
    							'quantity' 		=> $values['quantity'],
    							'data'			=> $_product,
    							'timestamp'     => time()
    
    						), $values, $key );
    					}
    				}
    			}

    I know I'm in the right direction, but I'm still missing something. The timestamp created now is the same for each order_item_id. So it's only adding one timestamp.
    The code I'm looking for is where to add "timestamp" in the values array, so that is is unique for each order_item_id.

    Any help would be greatly appreciated. I'm in over my head on this one.

    Kind regards

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic