Reputation: 1
I am building an e-commerce site with Woocommerce 3.6.4 + Wordpress 5.2.2.
I tried to disable the single product page of WooCommerce so that people can shop directly from my shop page.
Tried:
1. Add the code below to my child theme's functions.php file, didn't work.
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 );
2. Add the same code to my WooCommerce content-product.php file
. Didn't work.
3./wp-content/plugins/woocommerce/templates/content-product.php
Make these code as comments:
do_action( ‘woocommerce_before_shop_loop_item’);
do_action( ‘woocommerce_after_shop_loop_item’);
Become like this:
//do_action( ‘woocommerce_before_shop_loop_item’);
//do_action( ‘woocommerce_after_shop_loop_item’);
It removed the link to the shopping page, but didn't remove the single product page.
Any advice or help, please?
As a person who knows nothing about coding, this is literally driving me crazy!!!
Can anyone help me, please? Any suggestion would be great!!
Below is the wp_content/themes/my_theme/woocommerce/content-product.php:
`<?php
/**
* The template for displaying product content within loops
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 3.6.0
*/
defined( 'ABSPATH' ) || exit;
`
<li <?php wc_product_class( '', $product ); ?> data-product-id="<?php the_ID(); ?>">
<?php
/**
* Hook: woocommerce_before_shop_loop_item.
*
* @hooked woocommerce_template_loop_product_link_open - 10
*/
do_action( 'woocommerce_before_shop_loop_item' );?>
<?php if ('yes' != $themify->hide_product_image) : ?>
<?php
/**
* Hook: woocommerce_before_shop_loop_item_title.
*
* @hooked woocommerce_show_product_loop_sale_flash - 10
* @hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
?>
<?php endif; ?>
<div class="product-content">
<div class="product-content-inner-wrapper">
<div class="product-content-inner">
<?php
/**
* Hook: woocommerce_shop_loop_item_title.
*
* @hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* Hook: woocommerce_after_shop_loop_item.
*
* @hooked woocommerce_template_loop_product_link_close - 5
* @hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
?>
<div class="product-share-wrap">
<?php Themify_Wishlist::button() ?>
<?php if (themify_hide_quick_look()): ?>
<a onclick="return false;" data-image="<?php echo wc_placeholder_img_src() ?>" class="quick-look themify-lightbox" href="<?php echo add_query_arg(array('post_in_lightbox' => '1'), get_permalink()) ?>"><span class="tooltip"><?php _e('Quick Look', 'themify'); ?></span></a>
<?php endif; ?>
<?php if (themify_hide_social_share()): ?>
<?php get_template_part('includes/social-share', 'product'); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- /.summary -->
</li>
Upvotes: 0
Views: 4617
Reputation: 181
In your themes functions.php add the code,
// remove single product page link
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 );
// hide single product page completely
add_filter( 'woocommerce_register_post_type_product','hide_product_page',12,1);
function hide_product_page($args){
$args["publicly_queryable"]=false;
$args["public"]=false;
return $args;
}
solution was partly based on @Vitaly Gritsienko 's answer
Upvotes: 1