R
R
Rylezzz2019-01-10 03:24:09
WordPress
Rylezzz, 2019-01-10 03:24:09

WooCommerce - how to replace a product link in /shop with a link from attributes?

Hello.
The task is to implement a similar catalog in a simplified form on WP (you only need a Logo, Name, Link to the factory website). In order to properly filter alphabetically, I only thought of doing it all through WooCommerce, whichever is easier to implement:
1. in the mini-card: Factory logo, Factory name and when clicked, you go to the factory website
or
2. in the mini-card: Factory logo , Name of the factory, Active link to the factory website,
as I understand it, the link to the factory website in this case is written in the attributes so that you can simply import from Excel? How to insert it into the template in this case?
Since the site is not an IM and the product card is not needed at all, I googled this option to remove the link to the card itself:

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 );

If there is some more logical way to implement this task, I will only be glad to know. I don't want to statically typeset extra 25 pages to simulate an alphabetical filter.
I will be grateful for help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rylezzz, 2019-01-10
@Rylezzz

Yeah baby!
I understand that for many users this is baby talk, but for me it's a victory))
How I implemented my plan.
. Data output in the mini-card in the store /shop is done using hooks in the theme's content-product.php file.

original content-product.php
<?php

if ( ! defined( 'ABSPATH' ) ) {
  exit; // Exit if accessed directly
}

global $product, $woocommerce_loop;

// Ensure visibility
if ( empty( $product ) || ! $product->is_visible() ) {
  return;
}

// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) ) {
  $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 );
}

// Extra post classes
$classes = array();
if ($woocommerce_loop['columns'] == 2) {
  $classes[] = 'col-md-6';
}elseif($woocommerce_loop['columns'] == 4){
  $classes[] = 'col-md-3';
}elseif($woocommerce_loop['columns'] == 6){
  $classes[] = 'col-md-2';
}else{
  $classes[] = 'col-md-4';
}
?>
<div <?php post_class( $classes ); ?>>
<div class="product-item">
  <?php
  /**
   * woocommerce_before_shop_loop_item hook.
   *
   * @hooked woocommerce_template_loop_product_link_open - 10
   */
  do_action( 'woocommerce_before_shop_loop_item' );
  ?>
  <b><a href="<?php the_permalink(); ?>" class="products-warp"></b>
  <?php
  /**
   * woocommerce_before_shop_loop_item_title hook.
   *
   * @hooked woocommerce_template_loop_product_thumbnail - 10
   * @hooked woocommerce_show_product_loop_sale_flash - 10
   */
  do_action( 'woocommerce_before_shop_loop_item_title' );
  ?>
  <b></a></b>
  <div class="product-info">
  <b><a href="<?php the_permalink(); ?>"></b>
    <?php
      /**
       * woocommerce_shop_loop_item_title hook.
       *
       * @hooked woocommerce_template_loop_product_title - 10
       */
      do_action( 'woocommerce_shop_loop_item_title' );
    ?>
  <b></a></b>
  <?php
  /**
   * woocommerce_after_shop_loop_item_title hook.
   *
   * @hooked woocommerce_template_loop_rating - 5
   * @hooked woocommerce_template_loop_price - 10
   */
  <b>do_action( 'woocommerce_after_shop_loop_item_title' );</b>

  /**
   * woocommerce_after_shop_loop_item hook.
   *
   * @hooked woocommerce_template_loop_product_link_close - 5
   * @hooked woocommerce_template_loop_add_to_cart - 10
   */
  <b>do_action( 'woocommerce_after_shop_loop_item' );</b>
  ?>
  </div>
</div>
</div>

The first thing I did was remove the links from <?php the_permalink(); ?> , since the product card is not needed at all. Yes, it would be more elegant to figure it out and replace it with a function that displays the links I need, but, alas, there is no time for this.
Next - removed do_action( 'woocommerce_after_shop_loop_item_title' ); and do_action( 'woocommerce_after_shop_loop_item' ); , because I don't need the rating, the price and the "Add to cart" button.
I placed links to the sites of factories in the short description, respectively, in each product in the form
<a href="http://www.ararredamenti.it/" rel="noopener" target="_blank">www.ararredamenti.it</a>
(Excel to help). Accordingly, now we need to add a hook that would display a short description for us.
To do this, in the file /wp-content/plugins/woocommerce/includes/wc-template-hooks.php add
/**
 * Ссылки на фабрики в /shop.
 */
add_action( 'woocommerce_brands_link', 'woocommerce_template_single_excerpt', 10 );

I looked at this thing - 'woocommerce_template_single_excerpt' in the theme's content-single-product.php product card template - I noticed that this is part of a hook that displays product information.
Next, we add this hook to the content-product.php of the theme after the product header hook, as a result it turned out like this:
Changed content-product.php
<?php

if ( ! defined( 'ABSPATH' ) ) {
  exit; // Exit if accessed directly
}

global $product, $woocommerce_loop;

// Ensure visibility
if ( empty( $product ) || ! $product->is_visible() ) {
  return;
}

// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) ) {
  $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 );
}

// Extra post classes
$classes = array();
if ($woocommerce_loop['columns'] == 2) {
  $classes[] = 'col-md-6';
}elseif($woocommerce_loop['columns'] == 4){
  $classes[] = 'col-md-3';
}elseif($woocommerce_loop['columns'] == 6){
  $classes[] = 'col-md-2';
}else{
  $classes[] = 'col-md-4';
}
?>
<div <?php post_class( $classes ); ?>>
<div class="product-item">
  <?php
  /**
   * woocommerce_before_shop_loop_item hook.
   *
   * @hooked woocommerce_template_loop_product_link_open - 10
   */
  do_action( 'woocommerce_before_shop_loop_item' );
  ?>

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

  <div class="product-info">
    <?php
      /**
       * woocommerce_shop_loop_item_title hook.
       *
       * @hooked woocommerce_template_loop_product_title - 10
       */
      do_action( 'woocommerce_shop_loop_item_title' );
      do_action( 'woocommerce_brands_link' );
    ?>
  <?php

  ?>
  </div>
</div>
</div>

Finally, what you need
I know that the implementation is far from the best. I am familiar with php only at the level of such a rare picking of themes and plugins. As such, I do not claim to be an expert in any way. I hope it will be useful to those who, like me, were looking for a way to solve such a problem, because now I can immediately add 300 factories to the site by importing from Excel

C
coverme, 2019-01-10
@coverme

You can implement a plugin like this -
https://uk.wordpress.org/plugins/yith-woocommerce-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question