Отображение обычной цены WooCommerce в ячейке таблицы - PullRequest
0 голосов
/ 12 января 2020

Я пытаюсь заменить ячейки таблицы в приведенном ниже коде обычной ценой продукта woocommerce.

У меня есть этот код в моих функциях. php файл, который добавляет таблицу цен в область содержимого.

Как мне динамически изменить ячейку (class = "priceing table-full-price") для отображения обычной цены продукта?

add_filter ('the_content', 'insertPricingTable');
function insertPricingTable($content) {
if(is_single() && has_term( 'resin', 'product_cat' ) ) {
  $content.= '<table class="pricing-table">';
  $content.= '<tbody>';
  $content.= '<tr>';
  $content.= '<th>1 - 5</th>';
  $content.= '<th>6 - 11</th>';
  $content.= '<th>12+</th></tr>';
  $content.= '<tr>';
  $content.= '<td class="pricing-table-full-price">Full Price</td>';
  $content.= '<td class="pricing-table-35">35% OFF</td>';
  $content.= '<td class="pricing-table-45">45% OFF</td>';
  $content.= '</tr></tbody></table>';
}
return $content;
}

1 Ответ

0 голосов
/ 12 января 2020

Для этого вам нужно каким-то образом получить идентификатор продукта, который вы хотите sh, чтобы отобразить его цену. В вашем случае это можно сделать с помощью глобальной переменной $post.

    function insertPricingTable($content) {
    if(is_single() && has_term( 'resin', 'product_cat' ) ) {
      global $post;
      $product = new WC_Product($post->ID);
      $product_price = $product->get_price();
      $content.= '<table class="pricing-table">';
      $content.= '<tbody>';
      $content.= '<tr>';
      $content.= '<th>1 - 5</th>';
      $content.= '<th>6 - 11</th>';
      $content.= '<th>12+</th></tr>';
      $content.= '<tr>';
      $content.= '<td class="pricing-table-full-price">'.product_price.'</td>';
      $content.= '<td class="pricing-table-35">35% OFF</td>';
      $content.= '<td class="pricing-table-45">45% OFF</td>';
      $content.= '</tr></tbody></table>';
    }
    return $content;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...