繁体   English   中英

WordPress,Woocommerce店面相关产品

[英]Wordpress, Woocommerce Storefront Related Products

我想将“产品”页面上的“相关产品”移动到具有全角列的较低位置,因此我已经在functions.php文件中定义了以下内容:

// Move related products
   remove_action('woocommerce_after_single_product_summary','woocommerce_output_related_products',20);
   add_action('storefront_before_footer','woocommerce_output_related_products',20);

但是,通过这样做,相关产品现在可能已经超出了一些重要的循环,因为它们现在已显示在类别存档页面上。

有谁知道(a)如何将输出限制为产品页面(不显示:无;在样式表中)-或-(b)另一个定义的位置,可以将内容放置在div之外(下方),大概边栏,但保留相关产品与显示的产品页面的相关性?

我宁愿不要尝试对and的html输出进行重新设计,我相信您会了解这样做会产生很大的影响。

我猜想的另一个想法(虽然不理想或不正确)可能是使用jQuery。

编辑:这应该将输出限制为产品页面。

remove_action('woocommerce_after_single_product_summary','woocommerce_output_related_products',20);

add_action('storefront_before_footer','woo_related_product_addition');

function woo_related_product_addition() {

    global $post;

    if (function_exists( 'get_product' )) {
      add_action('storefront_before_footer','woocommerce_output_related_products',20);
    }
}

如果那对你不起作用...

remove_action('woocommerce_after_single_product_summary','woocommerce_output_related_products',20);

add_action('storefront_before_footer','woo_related_product_addition');

function woo_related_product_addition() {

    global $post;

    if (function_exists( 'get_product' )) {
    $product = get_product( $post->ID );

    if ($product->is_type( 'single' || 'grouped' || 'external' || 'variable' )) {
      add_action('storefront_before_footer','woocommerce_output_related_products',20);
    }
}
}

编辑2:然后,您可以通过执行类似的操作从存档页面中删除产品。

remove_action('woocommerce_after_single_product_summary','woo_related_product_removal');

function woo_related_product_removal() {

    global $post;

    if (function_exists( 'get_product' )) {
    $product = get_product( $post->ID );

    if (!$product->is_type( 'single' || 'grouped' || 'external' || 'variable' )) {
        remove_action('woocommerce_after_single_product_summary','woocommerce_output_related_products',20);
    }
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM