Skip to content

Instantly share code, notes, and snippets.

@rcstr
Last active August 8, 2019 14:19
Show Gist options
  • Save rcstr/f72c8dff0faa0910068b813b509b6d77 to your computer and use it in GitHub Desktop.
Save rcstr/f72c8dff0faa0910068b813b509b6d77 to your computer and use it in GitHub Desktop.

Revisions

  1. rcstr revised this gist Aug 8, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions woocommerce_add_cart_item_data.php
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,14 @@ function cstr_add_cart_item_data( $cart_item_data, $product_id ) {
    } else {
    return;
    }

    if ( empty( $cart_item_data['my_field'] ) ) {
    $cart_item_data['my_field'] = array();
    }

    // add my data.

    return $cart_item_data;
    }

    // Add item data to the cart.
  2. rcstr created this gist Aug 8, 2019.
    12 changes: 12 additions & 0 deletions woocommerce_add_cart_item_data.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?php

    function cstr_add_cart_item_data( $cart_item_data, $product_id ) {
    if ( isset( $_POST ) && ! empty( $product_id ) ) {
    $post_data = $_POST;
    } else {
    return;
    }
    }

    // Add item data to the cart.
    add_filter( 'woocommerce_add_cart_item_data', 'cstr_add_cart_item_data', 10, 2 );