• Hi

    We have two types of products in our website – “normal” product and special products. For the special products in our application to which we would like to add custom information. Information is unique for each one of that type of product. For example, some parameters like this:
    a=100
    b=200
    c=300
    etc.

    There is an PHP page from where we would like to add product to cart programmatically and add these custom parameters with its values.

    What is the best way to achieve this?

    Thanks.

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • As far as I know. First you have to create custom product meta field to hold some extra data.

    To display extra data use get_post_meta($product_id, 'your_product_meta_key', true);. Go here for more information.

    To display those data in cart page, go overriding templates/cart/cart.php file into your theme. Then find foreach loop which displaying added product to cart.

    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    // Loop
    }

    Then display your custom data inside that loop.

    Let me know how it helps for you.

    Thread Starter xmartens

    (@xmartens)

    Shouldn’t I add fields to the order rather than to the product?
    I am new to WordPress, I may not be correct in it’s terms.

    Based on your initial question, you have to add fields in product.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding custom parameters to an order programmatically’ is closed to new replies.