Last active
May 11, 2020 21:15
-
-
Save atxiii/7278426e19a8c668ad9dfbc1d9ce3170 to your computer and use it in GitHub Desktop.
Add ACF content to WooCommerce Description Tab on Single Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add content of Advance custom fields to description tab. | |
function add_acf_description_tab_content($data) { | |
woocommerce_product_description_tab(); | |
echo '<hr>'; | |
echo '<h3>Board Attributes</h3>'; | |
$ba = get_field('board_attributes'); // ba = board_attribute => get field board_attribute from acf | |
$ba_items = [ | |
// ['Attribute','value','image_url'] | |
['Terrian',$ba['terrain'],$ba['terrain_thumbnail']], | |
['Award',$ba['award'],''], | |
['Riding Level',$ba['riding_level'],''], | |
['Flex',$ba['flex'],''] | |
]; | |
template_table_for_ACF($ba_items); | |
} | |
function template_table_for_ACF($items){ | |
$tr = []; | |
$table_o = '<table class="shop_attributes"><tbody>'; | |
$table_c = '</tbody></table>'; | |
if($items && is_array($items)){ | |
foreach($items as $item){ | |
$img = !empty($item[2])? '<img src="'.$item[2].'" width="64" alt="" />' : '' ; | |
$item[1] = is_array($item[1]) ? print_name_desc_attributes($item[1]): $item[1] ; | |
if(!empty($item[1])) | |
array_push($tr, sprintf ('<tr><th>%s</th><td>%s <br> %s </td></tr>',$item[0],$item[1],$img)); | |
} | |
} | |
print_r($table_o . implode(' ' ,$tr) . $table_c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment