Support

Account

Home Forums Add-ons Repeater Field Help with repeat function by order quantity and order type (memberships)

Unread

Help with repeat function by order quantity and order type (memberships)

  • Hello! Thanks to you I have achieved good things, but I am stagnant:

    I have a website with ACF in which, I have a role called parent which buys a (PRODUCT “PLAN”), with the purchase of 1 product or plan, you can add 1 new user with the child role.

    At first I could not do that if I bought 5 products of the same memebresia or example plan (basic plan * 5) it would allow me to create 5 new users but this has already been solved, with some problems but that’s it.

    Now I need to make it work but I can’t do it, it is that if someone buys:

    plan 1
    plan 2
    plan 3, that is, several plans at once, this generates the permissions to add a new user for each plan or for the amount of each plan.

    this is my role

    add_action (‘woocommerce_order_status_completed’, ‘c7_order_completed’);
    function c7_order_completed ($ order_id) {
    $ order = wc_get_order ($ order_id);
    $ user_id = $ order-> get_customer_id ();
    $ plans = get_user_meta ($ user_id, ‘plans’, true);
    if (empty ($ plans)) $ plans = 0;
    foreach ($ order-> get_items () as $ item_id => $ item) {

    $ product_id = $ item [‘product_id’]; // product id
    $ product_qty = $ item [‘qty’]; // product quantity

    $ product_id = $ item-> get_product ();
    update_user_meta ($ user_id, ‘plans _’. $ plans .’_ order ‘, $ order_id);
    update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ order ‘,’ field_615a9e10ec6b6 ‘);
    update_user_meta ($ user_id, ‘plans _’. $ plans .’_ plan ‘, $ product_id-> get_id ());
    update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ plan ‘,’ field_615a9b29093b2 ‘);
    update_user_meta ($ user_id, ‘plans _’. $ plans .’_ child ‘, 0);
    update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ child ‘,’ field_615a9c1f093b3 ‘);
    wp_insert_post ([‘post_title’ => ‘test’. $ order_id. ‘-‘. $ product_id-> get_id ()]);

    }
    update_user_meta ($ user_id, ‘plans’, ($ plans + (1 * $ product_qty)));
    update_user_meta ($ user_id, ‘_planes’, ‘field_615a9a13a26bf’);
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.