WordPress

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.tr */
/* 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;
}
?>

İlgili Makaleler

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Başa dön tuşu