0

Please ask me if you don't understand any part of the following so I can elaborate.

I'm working on a collectibles site, the main feature being that you can register and browse all the collectibles and choose if you already have them, or if you want them. All this in the category view of the products.

What's already coded is the products (WooCommerce) with an ACF of a radio button with 3 options:

  • None
  • I want it
  • I own it

The thing I can't figure out, is how to save in each of the user_meta an option for the ACF for each product?

2 Answers 2

0

If I understood the question correctly, what you want can be achieved by storing serialised array of post_id and ACF value as key value pair.

So for each user, there will be user_meta which will contain post_ids and collectible_status.

0

The point of storing them in the user_meta is to be able to print the same post->id in another page while querying the same field. This is what I have so far.

So I have tried what you said earlier but I cant make it work:

/////////////////Colecionables
function coleccionables_producto() {
echo "</a>";
//foreach ($product_id as $id_prdct) {

include('connection-db.php');
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

//echo "SELECT * FROM `mg_usermeta` WHERE user_id = '" . "$user_id" . "';";
//echo "SELECT * FROM `mg_usermeta` WHERE user_id = '" . "$user_id" . "';";

global $current_user, $product, $post;
$user_id = $current_user->ID;
$product_id = $post->ID;
    if (isset($_POST['quiero'])) {
        $quieroPost = serialize(array_values($_POST['quiero']));
        update_user_meta( $user_id, 'lo_quiero', $quieroPost, false );
    } else if (isset($_POST['tengo'])) {
        $tengoPost = serialize(array_values($_POST['tengo']));
        update_user_meta( $user_id, 'lo_tengo', $tengoPost, false );
    } else {
        //no button pressed
    }

?>
<form id="wishlist-double" name="escoje" action="" method="POST" enctype="multipart/form-data">
    <input id="quiero" type="radio" name="quiero" value="<?php if(isset($user_data['quiero'][0])): echo $user_data['quiero'][0]; endif; ?>-<?php echo esc_attr($post->ID); ?>A" href="#">Lo Quiero</button>
    <input id="tengo" type="radio" name="tengo" value="<?php if(isset($user_data['tengo'][0])): echo $user_data['tengo'][0]; endif; ?>-<?php echo esc_attr($post->ID); ?>B" href="#">Lo Tengo</button>
    <div id="formMessages"></div>
</form>
<?
//}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.