R
R
Roman Govorov2018-11-03 17:43:51
WordPress
Roman Govorov, 2018-11-03 17:43:51

How to add "extra services" as a table in WP Wooccomerce?

Is there a plugin or maybe some kind of hack that can implement this?
5bddb3ade0ec4059035429.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sobolev, 2018-11-03
@san_jorich

Via custom post type with custom fields

O
Orkhan Hasanli, 2018-11-03
@azerphoenix

Hello!
1) install the ACF Pro plugin to create custom fields or tabs.
2) Install the ACF Tables plugin to add tables.
3) create the necessary set of custom fields, namely:
Repeater for the ability to add multiple tables. And put ACF Tables in it.
Result:
View from the admin panel
View from the front (you can style it to your liking)
Code for functions.php
Add a new tab to WooCommerce

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['params_tab'] = array(
    'title'   => __( 'Параметры', 'woocommerce' ),
    'priority'  => 60,
    'callback'  => 'params_tab'
  );
  return $tabs;
}

Display the contents of the table for this tab (functions.php). In this case, the ACF TABLE is nested within the ACF Repeater.
function params_tab() {
  if( have_rows('wc_pr_params') ):
      while ( have_rows('wc_pr_params') ) : the_row();
        // начало таблицы
          $table = get_sub_field( 'params_table' );
          if ( $table ) {
              echo '<table class="params_table" border="0">';
                  if ( $table['header'] ) {
                      echo '<thead>';
                          echo '<tr>';
                              foreach ( $table['header'] as $th ) {
                                  echo '<th>';
                                      echo $th['c'];
                                  echo '</th>';
                              }
                          echo '</tr>';
                      echo '</thead>';
                  }
                  echo '<tbody>';
                      foreach ( $table['body'] as $tr ) {
                          echo '<tr>';
                              foreach ( $tr as $td ) {
                                  echo '<td>';
                                      echo $td['c'];
                                  echo '</td>';
                              }
                          echo '</tr>';
                      }
                  echo '</tbody>';
              echo '</table>'.'<br/>';
          } // конец таблицы
      endwhile; 
  else :
      // no rows found
  endif;
}

That's all...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question