• Resolved mirazhyk

    (@mirazhyk)


    Hello!
    I have site with woocommerce and have part of code in hooks.php and it give an error
    $cat = get_the_terms($product->ID, ‘product_cat’);

    Notice: Undefined variable: product in?/home/suunto-ukraine.com/www/wp-content/themes/suunto/inc/functions/hooks.php?on line?181

    Notice: Trying to get property ‘ID’ of non-object in?/home/suunto-ukraine.com/www/wp-content/themes/suunto/inc/functions/hooks.php?on line?181
    global $product; – not resolve the problem
    Can anybody help me, pleasure?
    full code:
    function woocommerce_add_custom_text_before_product_title()
    {

    echo '<div class="hero-product__block">'; ?>
    <?php
    $terms = get_field('terms_select');
    
    if ($terms): ?>
        <ul class="product__tags">
            <?php foreach ($terms as $term): $term_link = get_term_link($term); ?>
                <li>
                    <?php
                    echo '<a href="';
                    echo $term_link;
                    echo '"';
                    echo ' style="background-color:';
                    echo get_field('tag_color', $term);
                    echo '">';
                    echo $term->name;
                    echo '</a></li>';
    
                    ?>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    
    
    <?php
    echo '</div>';
    $cat = get_the_terms($product->ID, 'product_cat');
    foreach ($cat as $categoria) {
        if ($categoria->parent == 0) {
            echo '<h4 class="parrent_cat">';
            echo $categoria->name;
            echo '</h4>';
        }
    }
    the_title('<h1 class="product_title entry-title">', '</h1>');

    Expand

    }

    add_action(‘woocommerce_single_product_summary’, ‘woocommerce_add_custom_text_before_product_title’, 5);

Viewing 1 replies (of 1 total)
  • Saif

    (@babylon1999)

    Hello @mirazhyk,

    Thank you for reaching out!

    Try retrieving the product ID using the get_id() method, according to this thread $product->ID no longer works.

    If that didn’t do it, consider hiring a WooExpert as custom solutions is not something we can assist with per our support policy. :?)

    Cheers!

Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce detailed product page’ is closed to new replies.