Ahh, I see – so it will take an array and serialize it when it gets imported? That makes more sense…
So it should be like:
Array
(
[0] => 9801
[1] => 10371
)
or this?
array(9801,10371)
I think I’m still missing a piece of the puzzle. Perhaps I’m missing something obvious.
In the spreadsheet is 14,000 records with JSON such as [“5667″,”93872”] for my custom field. I was planning on using a plugin to import this spreadsheet and create the new users. Do I need to format the sheet further before importing or is that code you provided to fix it after it’s imported?
Thanks for your help 🙂
Ahh, that makes sense – not sure how I missed that looking at it now. I’ve managed to convert my data to JSON in the spreadsheet with simple regex replace – do you know if ACF will take that or do I need to further convert the JSON to serialized?
My end goal is to be able to use a custom price for specified customers. I’ve figured that part out and the alter_price
function is working. the hard part, making that translate into the cart is where I’m struggling – it seems to be a different ball game.
function alter_price( $price ) {
$customer = get_field('customer',$product->id);
$special_customer_ids = [$customer];
if ( in_array( get_current_user_id(), $special_customer_ids, true ) && (get_field('special_price',$product->id))) {
$price = get_field('special_price');
return $price;
} else {
return $price;
}
}
add_filter( 'woocommerce_product_get_price', 'alter_price', 10, 1 );
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 20, 1);
function add_custom_price( $cart_obj ) {
// This is necessary for WC 3.0+
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Avoiding hook repetition (when using price calculations for example)
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
// Loop through cart items
foreach ( $cart_obj->get_cart() as $cart_item ) {
$customer = get_field('customer',$product->id);
$special_customer_ids = [$customer];
if ( in_array( get_current_user_id(), $special_customer_ids, true ) && (get_field('special_price',$product->id))) {
$newprice = get_field('special_price');
$cart_item['data']->set_price( $newprice );
}
}
}
I have been looking all over the place and been through several alterations of add_custom_price
. I think I should probably be using the_field
and a product ID. Any help is appreciated.
Amazing! Thank you so much. Just missing a comma on the end of ‘meta_value’.
Thanks again
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.