Example 1
// Add custom Data Sheets tab for WooCommerce
add_filter( 'woocommerce_product_tabs', 'add_data_sheets_product_tab' );
function add_data_sheets_product_tab( $tabs ) {
// ensure ACF is available
if ( !function_exists( 'get_field' ) )
return;
$tabs[] = array(
'title' => 'Data Sheets',
'priority' => 30,
'callback' => 'add_tab_product_data_sheets'
);
return $tabs;
}
// Add data for custom Data Sheets tab for WooCommerce
function add_tab_product_data_sheets( $tabs ) {
global $post;
$before_content = sprintf( '<div class="product-custom-fields"><div class="data-sheets">' );
if ( have_rows( 'supporting_documents' ) ):
while ( have_rows( 'supporting_documents' ) ): the_row();
$single_product_data_sheet_title = get_sub_field( 'file_title' );
$single_product_data_sheet = get_sub_field( 'upload_file' );
//$content .= '<p class="product-specs"><strong>Data Sheet: </strong>';
$content .= '<img src="/wp-content/uploads/2021/11/pdf-icon.png"> ';
$content .= sprintf( '<a class="product-datasheet-title" href="%s" target="_blank">%s</a>', esc_url(get_sub_field('upload_file')), esc_html(get_sub_field('file_title')));
$content .= '</p>';
endwhile;
$content .= sprintf( '</div>' );
endif;
if( $content ) {
echo $before_content . $content;
} else {
echo 'There are no specifications for this product.';
}
}
Example 2
// Add custom Specifications tab for WooCommerce
add_filter( 'woocommerce_product_tabs', 'add_specifications_product_tab' );
function add_specifications_product_tab( $tabs ) {
// ensure ACF is available
if ( !function_exists( 'get_field' ) )
return;
$tabs[] = array(
'title' => 'Specifications',
'priority' => 25,
'callback' => 'add_tab_product_specifications'
);
return $tabs;
}
// Add data for custom Specifications tab for WooCommerce
function add_tab_product_specifications() {
global $post;
$before_content = sprintf( '<div class="product-custom-fields"><div class="product-specs table-1"><table><tbody>' );
$max_gpm_terms = get_the_terms( $post->ID , 'max_gpm' );
$max_gpm = [];
foreach ( $max_gpm_terms as $max_gpm_term ) {
$max_gpm_list[] = esc_html($max_gpm_term->name );
}
$max_gpm = implode( ', ', $max_gpm_list );
if( $max_gpm ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name max-gpm"><a href="#" class="max-gpm">Max GPM</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $max_gpm );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$max_psi_terms = get_the_terms( $post->ID , 'max_psi' );
$max_psi = [];
foreach ( $max_psi_terms as $max_psi_term ) {
$max_psi_list[] = esc_html($max_psi_term->name );
}
$max_psi = implode( ', ', $max_psi_list );
if( $max_psi ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name max-psi"><a href="#" class="max-psi">Max PSI</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $max_psi );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$max_temp_terms = get_the_terms( $post->ID , 'max_temp' );
$max_temp = [];
foreach ( $max_temp_terms as $max_temp_term ) {
$max_temp_list[] = esc_html($max_temp_term->name );
}
$max_temp = implode( ', ', $max_temp_list );
if( $max_temp ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name max-temp"><a href="#" class="max-temp">Max Temp</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $max_temp );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$solids_handling_size_terms = get_the_terms( $post->ID , 'solids_handling_size' );
$solids_handling_size = [];
foreach ( $solids_handling_size_terms as $solids_handling_size_term ) {
$solids_handling_size_list[] = esc_html($solids_handling_size_term->name );
}
$solids_handling_size = implode( ', ', $solids_handling_size_list );
if( $solids_handling_size ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name max-temp"><a href="#" class="max-temp">Solids Handling Size</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $solids_handling_size );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$center_section_material_terms = get_the_terms( $post->ID , 'center_section_material' );
$center_section_material = [];
foreach ( $center_section_material_terms as $center_section_material_term ) {
$center_section_material_list[] = esc_html($center_section_material_term->name );
}
$center_section_material = implode( ', ', $center_section_material_list );
if( $center_section_material ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name center-section-material"><a href="#" class="center-section-material">Center Section Material</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $center_section_material );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$diaphragm_material_terms = get_the_terms( $post->ID , 'diaphragm_material' );
$diaphragm_material = [];
foreach ( $diaphragm_material_terms as $diaphragm_material_term ) {
$diaphragm_material_list[] = esc_html($diaphragm_material_term->name );
}
$diaphragm_material = implode( ', ', $diaphragm_material_list );
if( $diaphragm_material ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name diaphragm-material"><a href="#" class="diaphragm-material">Diaphragm Material</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $diaphragm_material );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$wetted_parts_material_terms = get_the_terms( $post->ID , 'wetted_parts_material' );
$wetted_parts_material = [];
foreach ( $wetted_parts_material_terms as $wetted_parts_material_term ) {
$wetted_parts_material_list[] = esc_html($wetted_parts_material_term->name );
}
$wetted_parts_material = implode( ', ', $wetted_parts_material_list );
if( $wetted_parts_material ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name wetted_parts_material"><a href="#" class="wetted_parts_material">Wetted Parts Material</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $wetted_parts_material );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$connection_terms = get_the_terms( $post->ID , 'connection' );
$connection = [];
foreach ( $connection_terms as $connection_term ) {
$connection_list[] = esc_html($connection_term->name );
}
$connection = implode( ', ', $connection_list );
if( $connection ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name connection"><a href="#" class="connection">Connections</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $connection );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$seat_material_terms = get_the_terms( $post->ID , 'seat_material' );
$seat_material = [];
foreach ( $seat_material_terms as $seat_material_term ) {
$seat_material_list[] = esc_html($seat_material_term->name );
}
$seat_material = implode( ', ', $seat_material_list );
if( $seat_material ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name seat_material"><a href="#" class="seat_material">Seat Material</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $seat_material );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$ball_material_terms = get_the_terms( $post->ID , 'ball_material' );
$ball_material = [];
foreach ( $ball_material_terms as $ball_material_term ) {
$ball_material_list[] = esc_html($ball_material_term->name );
}
$ball_material = implode( ', ', $ball_material_list );
if( $ball_material ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name ball_material"><a href="#" class="ball_material">Ball Material</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $ball_material );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$hardware_material_terms = get_the_terms( $post->ID , 'hardware_material' );
$hardware_material = [];
foreach ( $hardware_material_terms as $hardware_material_term ) {
$hardware_material_list[] = esc_html($hardware_material_term->name );
}
$hardware_material = implode( ', ', $hardware_material_list );
if( $hardware_material ):
$content .= sprintf( '<tr>' );
$content .= sprintf( '<td class="attribute-name hardware_material"><a href="#" class="hardware_material">Hardware Material</a></td>' );
$content .= sprintf( '<td>' );
$content .= sprintf( $hardware_material );
$content .= sprintf( '</td>' );
$content .= sprintf( '</tr>' );
endif;
$after_content .= sprintf( '</tbody></table></div></div>' );
if( $content ) {
echo $before_content . $content . $after_content;
} else {
echo 'There are no specifications for this product.';
}
}