1
我需要在WooCommerce上使用什麼,所以當您在商店/目錄頁面上看到產品時,它直接鏈接到聯盟網站,而不是通過單一產品頁面。定製商店頁面產品直接進入聯盟網站
然後如果可能的話,打開一個新標籤。
感謝
我需要在WooCommerce上使用什麼,所以當您在商店/目錄頁面上看到產品時,它直接鏈接到聯盟網站,而不是通過單一產品頁面。定製商店頁面產品直接進入聯盟網站
然後如果可能的話,打開一個新標籤。
感謝
更新:新增WC 3+兼容性
有3相關的定製掛鉤函數你的情況,你將需要自定義:
### 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文件中,或者也在任何插件文件中。
謝謝。你是否有這樣的代碼,這也適用於商店頁面的圖片和產品標題? – Chrissieg