从 Woocommerce 产品页面中删除单个页面的链接 [英] Remove link to single page from Woocommerce product page

查看:32
本文介绍了从 Woocommerce 产品页面中删除单个页面的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试删除指向 Woocommerce 插件单个产品页面的链接.在这个论坛上,很多人提出问题并且已经阅读了其中的大部分.但几乎所有这些问题都是陈旧的.然而,据我所知,我现在必须使用functions.php 和content-page.php 来实现这一点.

I have been trying to remove the link to the single product page of the Woocommerce plugin. On this forum many people asking questions about it and have read most of them. But nearly all of these questions are old. However as far as I understand now I have to use the functions.php and content-page.php to achieve this.

所以在阅读了 i-net 上的所有信息后,我在functions.php(在我的子主题文件夹中)中找到了这段代码

So after reading all the info on the i-net I came up with this code in the functions.php (which is inside my child theme folder)

if ( !function_exists('add_remove_hooks')):
function add_remove_hooks() {
    remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
    }
endif;
add_action( 'init', 'add_remove_hooks' );

我尝试了各种变体,例如只放在 remove_action 行中,而不是在函数中包装或在 add_action 函数中使用其他操作,但它们似乎都不起作用.但是,语法应该如此.

I have tried all kind of variants like only put in the remove_action rows, not wrapt in a function or use an other action in the add_action function, but none of them seem to work. The syntax, however, is as it should be.

content-page.php 的(部分)看起来像

The (part of)content-page.php looks like

<li <?php post_class( $classes ); ?>>
    <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

        <?php
            /**
             * woocommerce_before_shop_loop_item_title hook
             *
             * @hooked woocommerce_show_product_loop_sale_flash - 10
             * @hooked woocommerce_template_loop_product_thumbnail - 10
             */
            do_action( 'woocommerce_before_shop_loop_item_title' ); ?>

        <?php if($product_style == 'classic') { 
            do_action( 'woocommerce_shop_loop_item_title' );
            do_action( 'woocommerce_after_shop_loop_item_title' ); 
        } ?>

    <?php do_action( 'woocommerce_after_shop_loop_item' ); ?>

</li>

我不知道如何在 PHP 中进行调试,但我知道 WP 会使用"这些文件,因为如果我更改其中一个文件中的某些内容,我会在屏幕上看到它.但是,链接仍然存在.remove_action 不起作用.

I don't know how to debug in PHP, but I know the files are "used" by WP because if I change something in one of these files I see it on screen. However, the links are still in place. The remove_action is not working.

有人对如何实现这一点有其他建议吗?寻找什么?

Does anyobody have another suggestion on how to accomplish this? Of what to look for?

使用 WP 5.2 和 Woocommerce 3.0

Used WP 5.2 and Woocommerce 3.0

更新:

多亏了 Alfaraz,我才能够解决这个问题.将 remove_actions 放在子主题的 functions.php 中现在也可以使用.我没有意识到我还必须将 WP 中的活动主题设置为我的孩子主题.最终成功了.

Thanks to Alfaraz I was able to solve the problem. Putting the remove_actions in the functions.php of the child theme now also works. I didn't realize I also had to set the active theme in WP to my Child theme. That did the trick in the end.

推荐答案

将下面的代码放入主题的 functions.php 文件中.

Put below code in the functions.php file of your theme.

// Remove links to the product details pages from the product listing page of a WooCommerce store
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );

这篇关于从 Woocommerce 产品页面中删除单个页面的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆