• Resolved TallSam

    (@tallsam)


    Is there a way to remove the buy button from product category pages? So there is only a thumbnail, no buy button?

    Quick second question: is there a way to make the thumbnail on the product category page go straight to an affiliate link rather than going to the product listing first?

    Thanks,
    Sam

    https://wordpress.org/plugins/woocommerce/

Viewing 15 replies - 1 through 15 (of 26 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    1. You can use a CSS rule in your theme to hide buttons.
    2.You can change the link by editing the template which outputs it https://docs.woothemes.com/document/template-structure/

    Thread Starter TallSam

    (@tallsam)

    Thanks Mike

    Here is the page I am trying to work on: https://tall.life/shop/

    1. I tried to set visibility to hidden for the following class but didn’t seem to work, I’m kinda new to css…, thoughts?:
    /* hide woocommerce button */
    .button product_type_external {
    visibility: hidden !important;
    }

    2. I was looking through the woocommerce template files but I’m not sure which one outputs the link. Do you know which one it is?

    Thanks,
    Sam

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Missing ‘.’ dot before product_type_external.

    Actually its not a template. These 2 actions need unhooking https://github.com/woothemes/woocommerce/blob/38df18884874a1093f829ce37e81f16f9f5c58d1/includes/wc-template-hooks.php#L94-L95

    Thread Starter TallSam

    (@tallsam)

    Hi Mike,

    1. I added the dot, saved the css, but the buttons are still showing up. Thoughts?

    2. I’m not quite sure what you mean by unhooking. I tried deleting those lines but that just removed the link entirely, but I’m guessing that’s not what you meant. Wanted to quickly also mention that I plan on doing this only for some items, but not for others.

    Thanks,
    Sam

    Thread Starter TallSam

    (@tallsam)

    I found this solution for removing the button from my shop page:

    added this to functions.php: function remove_loop_button(){
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );
    }
    add_action(‘init’,’remove_loop_button’);

    But I’m still trying to figure out how to make the image on the shop page go directly to the affiliate link. Perhaps another snippet of code I can add to functions.php? Any thoughts?

    Thanks,
    Sam

    If you have WooCommerce version 2.5, you may be able to unhook the current link open tag and replace it with one of your own:

    remove_action ('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10);
    add_action ('woocommerce_before_shop_loop_item', 'my_link_open', 10);
    function my_link_open() {
      echo '<a href="http://some_domain.com">';
    }

    Sorry, not tested, and will have to leave it to others as to how to determine the appropriate new link.

    Thread Starter TallSam

    (@tallsam)

    Thanks lorro,

    That does work in that it goes to the link now instead of the product page. So now the next thing to do is to connect it not to a given link, but rather the associated affiliate link for that product.

    Also, I’d like to be able to specify which products act this way, and which ones act the regular way (going to the product page).

    Suggestions?

    Thanks,
    Sam

    Your my_link_open() function could contain something like:

    global $product;
    switch ($product->id) {
      case 1234:
        // affiliate product = "bag"
        echo '<a href="http://www.affiliate.com/?product=bag">';
        break;
      // etc: one case per affiliate product
      default:
        // link all other products to the relevant product page
        echo '<a href="' . get_the_permalink() . '">';
    }

    Not tested. Hope you can debug php!

    Thread Starter TallSam

    (@tallsam)

    Nice, getting closer here!

    Is there a way to say the href should be the affiliate link for that product id? Rather than specifying the href manually?

    I ask this because there will be maybe a hundred such products and this could save a lot of coding.

    Which leads me to another refinement: can you think of another way to say which products this will occur for besides listing their id? I’m imagining something like checking to see if the sku has the symbol # in it or something like that. Then all I have to do is add a # to the sku and clicking the product image on the shop page will go straight to the affiliate link. Any idea how to do this?

    Almost there, thanks for your time and patience!
    Sam

    Probably. What is the rule for determining the affiliate link?

    Thread Starter TallSam

    (@tallsam)

    Not entirely sure what you are asking so I will answer broadly hoping I get lucky šŸ™‚

    Most of the products that will be on my site will be for an affiliate and so have an affiliate link. This link will be manually pasted into the woocommerce product link field (though I eventually might automate this to pull products in from a xml file, perhaps with a plugin). At the same time that a product is added, I can put a # in the sku and when the function sees this in the sku, it makes the link the affiliate link, thereby sending the visitor directly to the affiliate site. That is what I’m hoping you can help me achieve anyway…

    In case you are curious, the reason I’m doing all this is because sometimes it is better to send traffic immediately to the affiliate, likely because they have a lot of stuff and a purchase of something besides the linked product is likely. Whereas other times, such as when they only have one product, it is better to send traffic only if purchasing the linked product is fairly certain.

    Thanks,
    Sam

    global $product;
    $sku = $product->get_sku();
    $position = stripos($sku, '#');
    if ($position === false) {
      // no # in sku so not an affiliate product
      $url = get_the_permalink();
    } else {
      // must be an affiliate product
      $url = $product->get_product_url();
    }
    echo '<a href="' . $url . '">';

    As before, not tested.

    Thread Starter TallSam

    (@tallsam)

    Well done, worked perfect!

    I just thought of a slightly sleeker way to make the decision. Rather than looking at sku, instead look at the affiliate link domain name. If it is in a list of specified domains, then it goes direct to the affiliate link. For example, I could have a list of two as follows: ForTheFit, LongTallSally, and so if an affiliate link has one of those domains in it, then the product image on the shop page links straight to the affiliate link rather than the product page.

    Sorry for wasting time with the sku approach, was just getting my head around it all. I could probably figure out how to do this last request, but would have to learn some php, and I’m already confused with javascript so… if you wouldn’t mind putting together the code for this last step, I’d greatly appreciate it, thanks!

    Sam

    Abstracting the domain name from the affiliate link and comparing it to a list is a bit much for here. Is it not simpler: if there is an external link then use it, if not, use the product page:

    global $product;
    $url = $product->get_product_url();
    if (!$url) {
      $url = get_the_permalink();
    }
    echo '<a href="' . $url . '">';

    As before, not tested.

    Thread Starter TallSam

    (@tallsam)

    I found I could just do what you showed me how to do with # but for searching for the domain in the product url. Now it will just be a matter of checking multiple possibilities, which I think I can figure out now.

    Thank you kindly for all your time, I learned a lot and this case is closed! The code is below for anyone who comes across this thread šŸ™‚

    Thanks again,
    Sam

    global $product;
    if( $product->is_type( ‘external’ ) ){
    $producturl = $product->get_product_url();
    $position = stripos($producturl, ‘forthefit’);
    if ($position === false) {
    // not a direct link affiliate address
    $url = get_the_permalink();
    } else {
    // must be a direct link affiliate product
    $url = $product->get_product_url();
    }
    }
    else {
    //no affiliate link available
    $url = get_the_permalink();
    }
    echo ‘‘;

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘Remove buy button from product category pages?’ is closed to new replies.