WooCommerce Sepete Ekle Düğmesini Ürün Sayfasına Yönlendirme

WooCommerce’de, sepete ekle düğmesini ürün sayfasına yönlendirmek için bir kod arıyordum. Müşteri sepete ekle butonuna bastığında  ürün detay sayfasına yönlendirmesi gerekiyordu. Peki neden böyle bir şeye ihtiyaç oldu derseniz. Eğer woocommerce eklentisini kullanıyor ama satış yapmıyorsanız 2 seçenek ortaya çıkıyor ya sepete ekle butonunu kaldıracaksınız yada bu kodu kullanarak ürün sayfasına yönlendirme yapacaksınız.
functions.php’ye eklemeniz gereken kod;

<?php
/* Buğra YAZAR */
/* bugrayazar.com */
/* WooCommerce sepete ekle düğmesini ürün sayfasına yönlendirme kodu */
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
if( $product->is_type( 'variable-subscription' ) || $product->is_type( 'variable' ) ) return $button;
// ==> HERE define your product category or categories in the array
$category = array( 'clothing', 'music' );
// Check that the custom url from product post meta data is not empty
$custom_url = get_post_meta( $post->ID, '_rv_woo_product_custom_redirect_url', true );
if( empty( $custom_url ) ) return $button;
// Check if the current product has a defined product category(ies)
if( ! has_term( $category, 'product_cat', $post->ID ) ) return $button;
$button_text = __( 'View product', 'woocommerce' );
$button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
?>
Category: WordPress
Tags: WordPress
Önceki yazı
Internal Link (Dahili Bağlantı) Nedir?
Sonraki yazı
WordPress: ‘Düzenleyici beklenmeyen bir hatayla karşılaştı’ Çözümü

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Fill out this field
Fill out this field
Lütfen geçerli bir e-posta adresi girin.
You need to agree with the terms to proceed

WordPress Referanslarımızı İnceleyin!
1.000’den fazla müşteri için oluşturduğumuz güzel web sitelerinden bazılarına göz atın.
WordPress desteği ve bakımı sunuyoruz
WordPress uzmanlarından oluşan ekibimiz tarafından desteklenen planlarla devam eden bakımın stresinden kurtulun.

İlgili Makaleler