定制Shop Page产品以直接进入会员站点 [英] Customizing Shop Page products to go straight to Affiliate Site
本文介绍了定制Shop Page产品以直接进入会员站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在WooCommerce上使用什么,因此,当您在商店/目录页面上看到产品时,它会直接链接到会员网站,而不是通过单个产品页面.
What do I need to use on WooCommerce, so when you see a product on the shop/catalogue page it links straight through to the affiliate site and not via the single product page.
然后尽可能在新标签页中打开.
Then if possible for that to open in a new tab.
谢谢
推荐答案
更新:添加了WC 3+兼容性
Update: Added WC 3+ compatibility
有3种与您的情况相关的自定义挂钩函数,您需要自定义:
There is 3 related custom hooked functions for your case, that you will need to customize:
### Custom Product link ###
// Removing the default hooked function
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
// Add back the hook to a custom function
add_action ( 'woocommerce_before_shop_loop_item', 'custom_loop_product_link', 10 );
function custom_loop_product_link() {
$custom_link = get_permalink( 16 ); // link to a custom page
echo '<a href="' . $custom_link . '" class="woocommerce-LoopProduct-link">';
}
### Custom add-to-cart link ###
add_filter( 'woocommerce_loop_add_to_cart_link', 'customizing_add_to_cart_button', 10, 2 );
function customizing_add_to_cart_button( $link, $product ){
// CUSTOM ADD TO CART text and link
$add_to_cart_url = site_url('/custom_link/');
$button_text = __('View now', 'woocommerce');
// compatibility with WC +3
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
$product_type = method_exists( $product, 'get_type' ) ? $product->get_type() : $product->product_type;
$link = sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button product_type_%s">%s</a>',
esc_url( $add_to_cart_url ),
esc_attr( $product_id ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product_type ),
esc_html( $button_text )
);
return $link;
}
### Custom link Redirect after add-to-cart ###
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect', 10, 1 );
function my_custom_add_to_cart_redirect( $url ) {
$url = get_permalink( 16 ); // an example: here redirect is on page ID 16
return $url;
}
该代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.
这篇关于定制Shop Page产品以直接进入会员站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文