#wordpress #woocommerce #wordpress-shortcode
#wordpress #woocommerce #wordpress-короткий код
Вопрос:
У меня есть шорткод, в который мне нужно динамически вставлять текущую категорию WordPress / WooCommerce.
Исходный шорткод
[content_control]
[product_table category="product-cateegory-name" columns="sku,name,cf:size,cf:pgk_qty,cf:case_qty,cf:case_wt,stock,price,buy,cf:dia_pitch,cf:length,cf:inner_box_q,cf:inner_box_length,cf:inner_box_width,cf:inner_box_height,cf:outer_box_qty,cf:outer_box_length,cf:outer_box_width,cf:outer_box_height,cf:outer_box_weight" column_breakpoints="all,all,all,all,all,all,all,all,all,none,none,none,none,none,none,none,none,none,none,none,none"]
[/content_control]
Я пытался
<?php echo do_shortcode("[content_control]"); ?>
<php
$cate = get_queried_object();
$cateID = $cate->term_slug;
?>
<?php echo do_shortcode("[product_table category="'. $cateID .'" columns="sku,name,cf:size,cf:pgk_qty,cf:case_qty,cf:case_wt,stock,price,buy,cf:dia_pitch,cf:length,cf:inner_box_q,cf:inner_box_length,cf:inner_box_width,cf:inner_box_height,cf:outer_box_qty,cf:outer_box_length,cf:outer_box_width,cf:outer_box_height,cf:outer_box_weight" column_breakpoints="all,all,all,all,all,all,all,all,all,none,none,none,none,none,none,none,none,none,none,none,none"]"); ?>
<?php echo do_shortcode("[/content_control]"); ?>
Но я думаю, что вставка переменной таким образом не сработает.
Я думаю, что есть что-то основное, чего мне не хватает
Ответ №1:
Это сработало. Мне пришлось экранировать "
s в PHP и соединить два аргумента в шорткоде с помощью ' . '
$cate = get_queried_object()->slug;
echo do_shortcode("[product_table category="' . $cate . ' " columns="sku,name,cf:size,cf:pgk_qty,cf:case_qty,cf:case_wt,stock,price,buy,cf:dia_pitch,cf:length,cf:inner_box_q,cf:inner_box_length,cf:inner_box_width,cf:inner_box_height,cf:outer_box_qty,cf:outer_box_length,cf:outer_box_width,cf:outer_box_height,cf:outer_box_weight"' . 'column_breakpoints="all,all,all,all,all,all,all,all,all,none,none,none,none,none,none,none,none,none,none,none,none"']"); ?>```