Woocommerce改变产品风格并将其显示在页面上

时间:2015-05-01 09:04:08

标签: wordpress woocommerce woothemes

提前抱歉我的近似英语。我想在特定产品类别的woocommerce上更改产品页面样式(不要显示图片和其他一些重要的布局更改)。已经制作它并且它可以工作,问题是我想在一个页面上显示这些产品。我尝试使用woocommerce集成短代码[product_page id = $ id],问题是我在content-single-product.php(在woocommerce文件夹中)创建的自定义样式和布局不使用此短代码。我试图在class-ws-shortcodes.php(woocommerce文件夹)上复制我的脚本,但它没有用。我应该怎么做才能在特定页面上显示产品,这些产品页面的真实风格(我创建的是自定义产品),而不是woocommerce短信代码?

提前感谢您的回答

3 个答案:

答案 0 :(得分:3)

有两种方法可以实现这一点,这取决于您是要编辑single-product.php还是content-single-product.php。两者都会让你得到相同的最终结果。

要执行前者,您可以使用默认的WordPress功能,并通过template_include

在给定条件下过滤模板
add_filter( 'template_include', 'so_29984159_custom_category_template' );
function so_29984159_custom_category_template( $template ){
    if ( is_single() && get_post_type() == 'product' && has_term( 'custom_category', 'product_cat' ) ) {
        $template = locate_template( 'single-product-custom.php' );
    }
    return $template;
}

或者,如果您更愿意创建自定义content-product.php模板部件,则可以使用WooCommerce的wc_get_template_part,其工作方式几乎相同。 从技术上讲,我认为你可以使用相同的条件逻辑,但我在这里调整它以指出WooCommerce在过滤器上提供的变量。

add_filter( 'wc_get_template_part', 'so_29984159_custom_content_template_part', 10, 3 );
function so_29984159_custom_content_template_part( $template, $slug, $name ){
    if ( $slug == 'content' && $name == 'product' && has_term( 'custom_category', 'product_cat' ) ) {
        $template = locate_template( 'content-product-custom.php' );
    }
    return $template;
}

在任何一种情况下,single-product-custom.phpcontent-product-custom.php都会出现在主题的根文件夹中。要将它们放在其他位置,只需更改locate_template()参数中的路径。

答案 1 :(得分:0)

您无法在wordpress的文件(即page.php)中进行编码以修改woocommerce页面。错误的方式。您只需将WooCommerce页面覆盖到主题文件夹中,然后修改您要执行的任何页面。所有模板/页面都位于woocommerce / templates文件夹中。

您可以在这里找到文档。

 http://docs.woothemes.com/document/template-structure/

答案 2 :(得分:0)

为单一产品视图编辑woocommerce / templates / content-single-product.php

相关问题