我想在简易数字下载插件中修改结帐,收据和其他页面。
作为他们的documentation,我已将该文件复制到我当前主题的文件夹/ edd_templates /
实际上,我有 2个不同的类别(研讨会,软件),我正在寻找一种方法来为每一个结帐页面显示不同的表 这些类别。
所以,我试图用这个:
<?php
$args = array(
'post_per_page' => '-1',
'post_type' => 'download',
'tax_query' => array(
array(
'taxonomy' => 'download_category',
'field' => 'slug',
'terms' => 'workshop'
)
)
);
$my_posts = get_posts( $args );
if ( $my_posts ) :
?>
// custom html table for first category goes here... //
<?php endif; ?>
<?php
$args1 = array(
'post_per_page' => '-1',
'post_type' => 'download',
'tax_query' => array(
array(
'taxonomy' => 'download_category',
'field' => 'slug',
'terms' => 'software'
)
)
);
$myy_posts = get_posts( $args1 );
if ( $myy_posts ) :
?>
// custom html table for second category goes here... //
<?php endif; ?>
但它会在结帐页面显示两个表格,无论您属于哪个类别...
我认为问题是我已经告诉wordpress显示这些html表只是在这些类别中有什么东西。不要过滤它们...
我该如何解决这个问题?
答案 0 :(得分:0)
你可以解决这个问题,其中一个我在下面给你看, 首先为您的愿望页面创建模板页面,例如Checkout
<?php
/**
* Template Name: Checkout
*
*/
然后将您的代码改为自定义模板文件。 接下来转到管理仪表板,然后选择自定义模板Checkout。
该页面将显示您的愿望输出。
答案 1 :(得分:0)
你的最后一段是对的,你没有放过任何过滤器。您需要先在购物车中获取产品类别。
<?php $cart_items = edd_get_cart_contents(); //get the contents in the cart
foreach ( $cart_items as $key => $item ): ?>
<?php
$terms = wp_get_post_terms( $item->ID, 'download_category' ); //get the categories of the items in the cart
foreach ( $terms as $term ) $categories[] = $term->slug; //form an array with those categories
然后,您需要检查该类别数组是否包含您的条款
if ( in_array( 'workshop', $categories ) ) {
// custom html table for first category goes here... //
}elseif ( in_array( 'software', $categories ) ){
// custom html table for second category goes here... //
else {
// custom html table for regular downloads goes here... //
}