Okay
  Public Ticket #1062604
Child Theme Functions
Closed

Comments

  •  2
    Trent started the conversation

    Hello, 

    Firstly great Theme. looks great. 

    Second I'm customizing the child theme to slightly change the way the product titles are displayed. Basically displaying some attributes if they exisit for a product. 

    The problem i have added the add_action( 'woocommerce_shop_loop_item_title', 'oxygen_child_woocommerce_loop_item_title' ); however wordpress still displays the oxygen_theme_loop_item_title. I have tried use remove_action for the oxgen_woocommerce_loop_item_title but with no  success. 

    would appreciate any help. I'm assuming it is something small and quick. I have attached the code of the funcion.php in my child theme for reference. 

    Thank you

    Trent


    <code>

    // This will enqueue style.css of child theme
    add_action( 'wp_enqueue_scripts', 'enqueue_childtheme_scripts', 100 );

    function enqueue_childtheme_scripts() {
    wp_enqueue_style( 'oxygen-child', get_stylesheet_directory_uri() . '/style.css' );
    }

    // Item Title

    remove_action( 'woocommerce_shop_loop_item_title', 'oxygen_woocommerce_loop_item_title', 10);


    function oxygen_child_woocommerce_loop_item_title() {
    global $product;
    $attributes = $product->get_attributes();

    ?>
    <div class="white-block description">
    <h4 class="title">
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </h4>

    <?php if(get_data('shop_product_category_listing')): ?>
    <span class="type">
    <?php the_terms($product->ID, 'product_cat'); ?>
    </span>
    <?php endif; ?>

    <?php if(isset($attributes['pa_rating'])){
            //if( isset($product->get_attribute['pa_region']) ) { // Add Region below the title. ?>                  

    <span class="type">
                    <i class="fa fa-trophy"> <?php echo $product->get_attribute('pa_rating'); ?></i>
                </span>
         
            <?php } ?>

    <?php if(get_data('shop_product_price_listing')): ?>
    <div class="divider"></div>

    <?php
    // Loop Item Price
    woocommerce_template_loop_price();
    ?>

    <?php endif; ?>

    <div class="error-container">
    </div>
    </div>
    <?php
    }

    add_action( 'woocommerce_shop_loop_item_title', 'oxygen_child_woocommerce_loop_item_title' );


  • [deleted] replied

    Hi Trent,

    After checking the code in our theme, I had to add an action to support this and I have modified this file:

    Download this file and replace it in this directory (of the theme): /inc

    So after you replace it, add the following code in functions.php (remove the existing one you tried to add):

    function action_show_product_rating() {
    global $product;
    $attributes = $product->get_attributes();

    if ( isset( $attributes['pa_rating'] ) ) {
    ?>
    <span class="type">
    <i class="fa fa-trophy"></i> <?php echo $product->get_attribute( 'pa_rating' ); ?>
    </span>
    <?php
    }
    }

    add_action( 'oxygen_woocommerce_after_shop_loop_category', 'action_show_product_rating', 10 );

    This should work for you.

  •  2
    Trent replied

    Legendary. Works a treat. 

    I did reply to email but bounced back. Thank you for the prompt solution. Greatly appreciated. 

  • [deleted] replied

    Hi Trent,

    Glad to hear that :)

    Will set this ticket as solved from here.