Just a bit of code that might be helpful to someone else.
The following goes in your theme's function php file:
add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_tp', 10, 2 );
function wc_checkout_description_tp( $other_data, $cart_item ){
//re-convert the fpd dtails from the json sting to an array
$fpd_detail_arr = json_decode( html_entity_decode( stripslashes( $cart_item['fpd_data']['fpd_product'] ) ), true );
//remove the first element as we are not dealing with shadows
$fpd_elems_arr = array_slice($fpd_detail_arr[0]['elements'], 1);
//loop each element and set the details to a var
foreach($fpd_elems_arr as $elem_key => $element_arr){
foreach($element_arr as $key => $value){
//the currentColor value is set inside yet another array
if(is_array($value)){
foreach($value as $val_key => $val_val){
if( $val_key == 'currentColor' && !empty($val_val) ){
$fpd_detail_value = $val_val;
}
}
}
//set the title value
else{
if( $key == 'title' && !empty($value) ){
$fpd_detail_name = trim($value);
}
}
}
//add the name and value pair to the detail array
$other_data[] = array(
'name' => $fpd_detail_name,
'value' => $fpd_detail_value
);
}
//return the final detail array
return $other_data;
}
Best Answer
M
Morgan Creech
said
almost 9 years ago
This is the code to get the description of your products in the cart. See attached for how it looks on my website.
Is there anyway that inserting this code into the theme's function php file could crash my website, or are the two events entirely unrelated...?
D
Davorin Savovic
said
over 8 years ago
Fantastic! Thank you life-saver!!!
M
Mark
said
over 8 years ago
Any updates with this after 7 months? I couldn't get this working
M
Mark
said
over 8 years ago
Got this working. My problem is that it shows all the elements from the canvas. in my shopping cart. How can I change it that it only shows selected variation?
Roger Beaujard
said
about 8 years ago
@Mark I have a solution to limit the output and also a bonus to swap out the hex vals for color names. First to limit what elements are shown simply add an if statement to the last block. Like so:
//add the name and value pair to the detail array
if($fpd_detail_name == 'T-Shirt') {
$other_data[] = array(
'name' => $fpd_detail_name,
'value' => $fpd_detail_value
);
}
You'l want to pay attention to the part:
if($fpd_detail_name == 'T-Shirt') {
You can change "T-Shirt" to whatever you want to KEEP. Or you could use a != and EXCLUDE "T-Shirt" and keep everything else. I suppose you could build a switch if you'd like to keep more than one thing but I'm sure you can see what's happening here.
Bonus: Here is some code you can use to switch out the hex vals for color names. Add this to the block just above the last one:
//the currentColor value is set inside yet another array
if(is_array($value)){
foreach($value as $val_key => $val_val){
if( $val_key == 'currentColor' && !empty($val_val) ){
$fpd_detail_value = $val_val;
// *** Swap out Hex for Color Names ***
switch ($fpd_detail_value) {
case "#000000":
$fpd_detail_value = "Black";
break;
case "#ffffff":
$fpd_detail_value = "White";
break;
case "#ff0000":
$fpd_detail_value = "Red";
break;
case "#cccccc":
$fpd_detail_value = "Heather";
break;
case "#ffff00":
$fpd_detail_value = "Yellow";
break;
case "#003366":
$fpd_detail_value = "Navy";
break;
case "#33cc33":
$fpd_detail_value = "Green";
break;
}
}
}
The custom parts are after "*** Swap out Hex for Color Names ***". Here we are just checking and resetting the final var to what we want.
Hope this helps some peeps ;)
-RJB
G
Gregory St. Gelais
said
about 7 years ago
How would you get the description on the admin order page?
Morgan Creech
Just a bit of code that might be helpful to someone else.
The following goes in your theme's function php file:
This is the code to get the description of your products in the cart. See attached for how it looks on my website.
- Oldest First
- Popular
- Newest First
Sorted by Oldest Firstalexus
Morgan Creech
This is the code to get the description of your products in the cart. See attached for how it looks on my website.
rady kal
Thanks Morgan for sharing. Good approach!
Charles Heller
Is there anyway that inserting this code into the theme's function php file could crash my website, or are the two events entirely unrelated...?
Davorin Savovic
Fantastic! Thank you life-saver!!!
Mark
Any updates with this after 7 months? I couldn't get this working
Mark
Got this working. My problem is that it shows all the elements from the canvas. in my shopping cart. How can I change it that it only shows selected variation?
Roger Beaujard
@Mark I have a solution to limit the output and also a bonus to swap out the hex vals for color names. First to limit what elements are shown simply add an if statement to the last block. Like so:
You'l want to pay attention to the part:
You can change "T-Shirt" to whatever you want to KEEP. Or you could use a != and EXCLUDE "T-Shirt" and keep everything else. I suppose you could build a switch if you'd like to keep more than one thing but I'm sure you can see what's happening here.
Bonus: Here is some code you can use to switch out the hex vals for color names. Add this to the block just above the last one:
The custom parts are after "*** Swap out Hex for Color Names ***". Here we are just checking and resetting the final var to what we want.
Hope this helps some peeps ;)
-RJB
Gregory St. Gelais
-
Adding Fancy Products to Categories
-
Shortcode for specfic product designer
-
What theme is recommended to use with FPD ?
-
Exclude Image from export
-
Google Font Family adds extras
-
Floating Dialog box
-
Uploadzone not working
-
Image transparency like in T-shirt demo
-
How do I get clipart
-
What does the LOAD button do / what is it for?
See all 2204 topics