function shop_remove_attributes( $attributes ) {
if( is_shop() ){
if( isset( $attributes['pa_color'] ) ){
unset( $attributes['pa_color'] );
}
if( isset( $attributes['pa_color2'] ) ){
unset( $attributes['pa_color2'] );
}
}
return $attributes;
}
add_filter( 'woocommerce_product_get_attributes', 'shop_remove_attributes' );exclude edeceğiniz bölümler:
pa_color
pa_color2
Hocam kodu şu şeikilde yaptım ama olmadı nerede hata yapıyorum sizce
ve şöyle de hata alıyorum
PHP kod değişiklikleriniz wp-content/themes/yanka/functions.php dosyasındaki satır 53 yüzünden geri alındı. Lütfen düzeltin ve tekrar kaydetmeyi deneyin.
Cannot redeclare shop_remove_attributes() (previously declared in wp-content/themes/yanka/functions.php:53)Gizle
l
function custom_attributes_display(){
global $product;
function shop_remove_attributes( $attributes ) {
if( is_shop() ){
if( isset( $attributes['pa_yakit-ekonomisi'] ) ){
unset( $attributes['pa_yakit-ekonomisi'] );
}
if( isset( $attributes['pa_yakit-ekonomisi'] ) ){
unset( $attributes['pa_yakit-ekonomisi'] );
}
}
return $attributes;
}
add_filter( 'woommerce_product_get_attributes', 'shop_remove_attributes', 20);
// Just for simple products
if( ! $product->is_type( 'simple' ) ) return;
$loop_count = 0;
echo '<div>';
// Get the attributes taxonomy slugs (Updated and dynamic now)
$attributes_taxonomy = $product->get_attributes();
// OR set an indexed array of taxonomy slug (key) and name (value) to chose which ones, like:
// $attributes_taxonomy = array('pa_nopeus' => 'Nopeus', 'pa_liito' => 'Liito, 'pa_vakaus' => 'Vaukaus' );
foreach( $attributes_taxonomy as $taxonomy => $attribute ) {
// Getting the term names of an attribute (set in a coma separated string if many values)
$attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );
$terms_string = implode( ',', $attribute_terms );
// Displays only if attribute exist for the product
if( count( $attribute_terms ) > 0 ){ // Updated
echo '<p style="border:solid">'.$attribute->get_name().' : '.$terms_string.'</p>';
// Separating each number by a " | " (Updated and dynamic now)
$attr_count = count( $attributes_taxonomy );
$loop_count++;
}
}
echo '</div>';
}