• Hi,
    Thank you for a great plugin!
    It works great with standard products, but we use it in a website where users can book video visit with prisoners(Regular Visits closed due to Covid19 in Thailand).
    Each user can register 2 prisoners (saved as user_meta: prisoner_1 and prisoner_2 ) and can book a video visit once a month per prisoner.
    Please could you help me to make the limit apply to once a month per prisoner, using the above meta_keys instead of once a month per user_id?

    We will really appreciate any help you can afford us.
    Many thanks and regards,
    Charles

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Algoritmika

    (@algoritmika)

    Hi @correctshop,

    Thank you.

    Not sure if I understood it correctly. When your customer orders a product (i.e. “video visit”) – does he need to select which one of the prisoners he is booking it for before adding product to the cart? And if he does – does this information (i.e. prisoner_1 or prisoner_2) is then passed and saved in order? And if so – is it stored as order items meta?

    Thread Starter Charles

    (@correctshop)

    Hi. Thanks so much for the reply.

    The user first registers where they can save the details for 2 prisoners and numbers. (user_meta: prisoner_1 and prisoner_1_number).
    Then they login and choose a date and time, and in the checkout page they choose which prisoner they want to visit online.

    I use a code snippet to collect that information in checkout page:

    add_action(‘woocommerce_before_order_notes’, ‘wps_add_select_checkout_field’);
    function wps_add_select_checkout_field( $checkout ) {
    // Get Current User

    $user_id = get_current_user_id();

    // Setup Variable Values from Metadata
    $pris_1 = get_user_meta( $user_id, ‘prisoner_1’, true ) . ‘ – ‘ . get_user_meta( $user_id, ‘prisoner_1_number’, true );
    $pris_2 = get_user_meta( $user_id, ‘prisoner_2’, true ) . ‘ – ‘ . get_user_meta( $user_id, ‘prisoner_2_number’, true );
    // Select Prisoner PHP Code
    echo ‘<h2>’.__(‘????????????????????’).'</h2>’;

    woocommerce_form_field( ‘prisoner’, array(
    ‘type’ => ‘select’,
    ‘class’ => array( ‘wps-drop’ ),
    ‘label’ => __( ‘???????????????????????????’ ),
    ‘options’ => array(
    ‘blank’ => __( ‘???????????????’, ‘wps’ ),
    $pris_1 => __( $pris_1, ‘wps’ ),
    $pris_2 => __( $pris_2, ‘wps’ ),
    )
    ),

    $checkout->get_value( ‘prisoner’ ));

    }

    And it is saved with the following snippet:

    add_action(‘woocommerce_checkout_update_order_meta’, ‘wps_select_checkout_field_update_order_meta’);
    function wps_select_checkout_field_update_order_meta( $user_id ) {

    if ($_POST[‘prisoner’]) update_post_meta( $user_id, ‘prisoner’, esc_attr($_POST[‘prisoner’]));

    }

    I have a stage site but not sure if I can post admin access details here.
    https://cida.site/dev2

    Thread Starter Charles

    (@correctshop)

    Sorry. Forgot to provide test user details:

    Username: testuser
    Password: 1234567

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @correctshop,

    Thanks for the info. Let me think this through – I will get back to you shortly.

    P.S. One note – in your last snippet, where you use woocommerce_checkout_update_order_meta, it’s actually $order_id, not $user_id, so when you are updating meta, you are updating it for order, not for user.

    Thread Starter Charles

    (@correctshop)

    Yes, that’s correct, because it relates to the visit being booked for that particular prisoner in that particular booking and may not be the same for the next booking (Although, out of the 6k users, there are only about 10% that have two prisoners registered in their user_meta). Our biggest problem is prevent the same prisoner being allowed more than one visit per month.
    At the moment I’m having to search out duplicates manually :).
    We will buy the pro version of your plugin today.

    Thank you so very much!
    Best regards,
    Charles

    Thread Starter Charles

    (@correctshop)

    Hi,
    While we waiting for your reply about limiting bookings per prisoner, I’m trying to prevent users at least from making another booking for prisoners in other buildings(Each building is a different product number, but all in the one category). But I’m having some trouble limiting by category. In the “limits” tab, I’ve tried enabling ‘All products as well as enabling ‘Per Product Category’. But user is still able to book for a different building although they the limit works if they try to book again for the same building. In Products>Category, the list of bookings does populate. Not sure what I’m doing wrong.
    Best regards,
    Charles

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Limit per User Meta’ is closed to new replies.