Support

Account

Home Forums ACF PRO Woocommerce custom field item cart

Solved

Woocommerce custom field item cart

  • Hello,

    As I said in my previous post :
    Custom fields for registration woocommerce

    it was not what I needed, even if I used to make it work with user registration with the help of @James.

    I want customers to be able to give their weight to buy a bike. But if they buy 2 bikes for different people, they need to give 2 different weight.

    After trying every kind of snippets I found (I didn’t understand if that post on acf support had the solution), I think that I could create a form on the product page with my measurement fields, which allow customers to set the values, maybe detect the add to cart to register my custom fields while the product is added, and voilà.

    And… the fields will be modified by each client and if a client change the value while another add to cart… it won’t work… pffff

    Do someone have an idea about where I must search for ? It’s only wordpress: a field to be added temporarily to a post…

  • Hi @wax

    If you want to add the form to the product page, then you need more advanced code and logic. Unfortunately, I can only guide you with the logic. I’m sorry about that.

    Like my answer in your other thread, you can use the repeater field and add it to the front-end by using this code:

    acf_form(array(
        'form' => false,
    ));

    This will strip the ACF’s form tag and let you add it in the add to cart form instead.

    When a user clicked the add to cart button, you can get the repeater value by using this code:

    $repeater_values = $_POST['acf']['field_1234567890abc'];

    Where ‘field_1234567890abc’ is the field key of the repeater. At this time, you need to modify the cart content so it can hold the extra information. Here’s an example how to do it: http://wordpress.stackexchange.com/questions/138595/add-custom-variable-to-cart-content. I’m not sure if it will work or not, though. Please consult to WooCommerce for more information.

    I’m not sure if you need to modify the order or not after this process, but I guess you can try it out to find out 🙂

    Hope this makes sense.

  • Hi James,

    I’m trying to understand your advices since 1 hour but I’m a bit lost.

    Example : The customer can buy a bike for him and another for his little girl. So he must give 2 different weight. So I must have a form on my product page but the data must be recorded as new item cart.
    So what I need is just a field Weight and not a repeater one ?

    Another thing that I don’t understand : I’ve tried (for the first time) acf_form on single product page. It’s funny, I didn’t know that we could make all the data recordable in front. But I can not record the weight on products data cause another client can be on the same product buying it and giving another weight. And I don’t know a way to block the record during this time.

  • Ok. I did it the easiest way, by adding customs fields to checkout.
    ^^
    Good explanations there :
    http://www.portmanteaudesigns.com/blog/2015/02/04/woocommerce-custom-checkout-fields-email-backend/

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Woocommerce custom field item cart’ is closed to new replies.