Link directly to merchant's site, bypass single product page
This article explains how to make all of your product links go directly to the merchants/vendors websites, bypassing the single product page entirely.
This replaces ALL links (including links in your sidebars, search results and category pages) to single product pages with direct links to the merchants' sites. This is also compatible with the WooCommerce Cloak Affiliate Links plugin. This does not work with non-datafeedr imported products.
- 1
-
Create a custom plugin
If you haven't done so already, create a custom plugin.
- 2
-
Add custom code
Add the following code to your custom plugin file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<?php /** * This custom code forces all product links to link to the merchant's * site instead of the single product's page. * * @param string $post_link The post's permalink. * @param WP_Post $post The post in question. * @param bool $leavename Whether to keep the post name. * @param bool $sample Is it a sample permalink. * * @return string Returns updated $post_link. */ function mycode_force_all_product_links_to_merchants_site( $post_link, $post, $leavename, $sample ) { // If post is not a product, return default $post_link. if ( 'product' != $post->post_type ) { return $post_link; } // If this product was not added by the DFRPSWC plugin, return default $post_link. if ( ! dfrpswc_is_dfrpswc_product( $post->ID ) ) { return $post_link; } // If WCCAL is activated, get WCCAL-generated URL, else use dfrapi_url to get $post_link. if ( class_exists( 'Wccal' ) ) { $wccal = new Wccal_Product_External( $post ); $post_link = $wccal->get_product_url(); } else { $product = get_post_meta( $post->ID, '_dfrps_product', true ); $post_link = dfrapi_url( $product ); } // Return $post_link. return $post_link; } add_filter( 'post_type_link', 'mycode_force_all_product_links_to_merchants_site', 15, 4 ); - 3
-
Save
Save your custom plugin changes.