Home › Forums › WoodMart support forum › Link Failure – Forwarding – Productpage – Brands Image Icon › Reply To: Link Failure – Forwarding – Productpage – Brands Image Icon
November 3, 2018 at 5:30 pm
#86962
Cero
Participant
Can you check this? Not working…
<?php
/**
* Enqueue script and styles for child theme
*/
function woodmart_child_enqueue_styles() {
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'woodmart-style' ), woodmart_get_theme_info( 'Version' ) );
}
add_action( 'wp_enqueue_scripts', 'woodmart_child_enqueue_styles', 1000 );
/**
* Query string archve
*/
add_filter( 'woodmart_brands_link', function( $link, $brand ){
return get_term_link( $brand->term_id, $brand->taxonomy );
}, 10, 2 );
//Warenkorb Button umbenennenung auf kaufen
add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // 2.1 +
function woo_custom_single_add_to_cart_text() {
return __( 'kaufen', 'woocommerce' );
}
// remove version from rss
add_filter('the_generator', '__return_empty_string');
// No need to do anything if there isn't any content
if ( empty( $content ) ) {
return $content;
}
// Define links array
$links = array();
// Get page content
libxml_use_internal_errors(TRUE);
$html = new DomDocument;
$html->loadHTML( $content );
$html->preserveWhiteSpace = false;
// Loop through all content links
foreach( $html->getElementsByTagName( 'a' ) as $link ) {
// If the title attribute is already defined no need to do anything
if ( ! empty( $link->getAttribute( 'title' ) ) ) {
continue;
}
// Get link text
$link_text = $link->textContent;
// Save links and link text in $links array
if ( $link_text ) {
$links[$link_text] = $link->getAttribute( 'href' );
}
}
// Loop through links array and update post content to add link titles
if ( ! empty( $links ) ) {
foreach ( $links as $text => $link ) {
if ( $link && $text ) {
$text = esc_attr( $text ); // Sanitize
$text = ucwords( $text ); // Captilize words (looks better imo)
$replace = $link .'" title="'. $text .'"'; // Add title to link
$content = str_replace( $link .'"', $replace, $content ); // Replace post content
}
}
}
// Return post content
return $content;
}
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' defer ";
}
//* TN - Remove Query String from Static Resources
function remove_css_js_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_css_js_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_css_js_ver', 10, 2 );
/*SUPORT BRANDS*/
function woodmart_product_brand() {
global $product;
$attr = woodmart_get_opt( 'brands_attribute' );
if( ! $attr || ! woodmart_get_opt( 'product_page_brand' ) ) return;
$attributes = $product->get_attributes();
if( ! isset( $attributes[ $attr ] ) || empty( $attributes[ $attr ] ) ) return;
$brands = wc_get_product_terms( $product->get_id(), $attr, array( 'fields' => 'all' ) );
if( empty( $brands ) ) return;
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} else {
$link = get_permalink( wc_get_page_id( 'shop' ) );
}
$classes = ( woodmart_get_opt( 'product_brand_location' ) == 'sidebar' && ! woodmart_loop_prop( 'is_quick_view' ) ) ? 'widget sidebar-widget' : '';
echo '<div class="woodmart-product-brands '. esc_attr( $classes ) .'">';
foreach ($brands as $brand) {
$image = get_term_meta( $brand->term_id, 'image', true);
$filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $attr ) );
$attr_link = apply_filters( 'woodmart_brands_link', add_query_arg( $filter_name, $brand->slug, $link ), $brand );
if( ! empty( $image ) ) {
echo '<div class="woodmart-product-brand">';
echo '<a href="' . esc_url( $attr_link ) . '"><img src="' . esc_url( $image ) . '" title="' . esc_attr( $brand->slug ) . '" alt="' . esc_attr( $brand->slug ) . '" /></a>';
echo '</div>';
}
}
echo '</div>';
}