Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #910417
    isakfyksen
    Participant

    Hi,
    I’m trying to modify x_woocommerce_template_loop_product_title() and x_woocommerce_shop_product_thumbnails(). I have created the function custom_product_query( $foo, $bar ), which returns a query string where $bar is equal to $foo if $foo is set. This is added to the end of the hrefs of the two -tags in the woocommerce functions, and it works fine, no problems there.

    The problem is that no matter how I implement the changes to the woocommerce functions they won’t display propperly.

    If I create x-child/framework/functions/global/plugins/woocommerce.php and make the changes there, they are ignored and wordpress uses the original x file regardless.

    If I force it to require the child theme file from x-child/functions.php it gives me an php error, since the original file gets required as well, and this creates function conflicts. (didn’t really expect that to work though).

    What I ended up doing was to add the new functions to x-child/functions.php and use add/remove_action to unhook the original x functions and hook in the new functions. Just like x/framework/functions/global/plugins/woocommerce.php does to the original woocommerce functions. However, the original x fuctions won’t unhook, and so the thumbnails and titles are instead displayed twice (once for my new function, and once for x).

    So in the end I got it working by commenting out the add_action()-statement for the x functions, directly in x/framework/functions/global/plugins/woocommerce.php. This will obviously be removed the next time I update, and then I’ll have to go in and do it again.

    But I don’t see why it’s not working propperly, so questions as follows:

    • Why is x-child/framework/functions/global/plugins/woocommerce.php ignored?
    • Why is remove_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_template_loop_product_title', 10 ); and remove_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_shop_product_thumbnails', 10 ); not working?
    • Am I doing something wrong?

    (info: the new functions in x-child are prefixed with c_ instead of x_, so it won’t cause conflicts)

    #910418
    isakfyksen
    Participant

    Hi,
    I’m trying to modify x_woocommerce_template_loop_product_title() and x_woocommerce_shop_product_thumbnails(). I have created the function custom_product_query( $foo, $bar ), which returns a query string where $bar is equal to $foo if $foo is set. This is added to the end of the hrefs of the two <a>-tags in the woocommerce functions, and it works fine, no problems there.

    The problem is that no matter how I implement the changes to the woocommerce functions they won’t display propperly.

    If I create x-child/framework/functions/global/plugins/woocommerce.php and make the changes there, they are ignored and wordpress uses the original x file regardless.

    If I force it to require the child theme file from x-child/functions.php it gives me an php error, since the original file gets required as well, and this creates function conflicts. (didn’t really expect that to work though).

    What I ended up doing was to add the new functions to x-child/functions.php and use add/remove_action to unhook the original x functions and hook in the new functions. Just like x/framework/functions/global/plugins/woocommerce.php does to the original woocommerce functions. However, the original x fuctions won’t unhook, and so the thumbnails and titles are instead displayed twice (once for my new function, and once for x).

    So in the end I got it working by commenting out the add_action()-statement for the x functions, directly in x/framework/functions/global/plugins/woocommerce.php. This will obviously be removed the next time I update, and then I’ll have to go in and do it again.

    But I don’t see why it’s not working propperly, so questions as follows:

    • Why is x-child/framework/functions/global/plugins/woocommerce.php ignored?
    • Why is remove_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_template_loop_product_title', 10 ); and remove_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_shop_product_thumbnails', 10 ); not working?
    • Am I doing something wrong?

    (info: the new functions in x-child are prefixed with c_ instead of x_, so it won’t cause conflicts)

    Sorry, forgot to put code tags on the <a>-tag the first time around x)

    #910692
    Christian
    Moderator

    Hey there,

    1. This could not be overridden by copying the file in the child theme because it contains functions and not front-end views.

    2. Please try changing the priority from 10 to 99 or higher so it would be remove_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_template_loop_product_title', 99 );

    3. No. Just try changing the priority.

    Thanks.

    #910751
    isakfyksen
    Participant

    I’ve already tried lower and higher priority for the remove_action()s, but it has no effect.

    I just now tried with the specific 99 you suggested, but still no effect.

    Any other ideas?

    #911342
    Darshana
    Moderator

    Hi there,

    Can you please try the following suggestion (http://stackoverflow.com/a/32123769/1978139).

    Hope that helps.

    #912080
    isakfyksen
    Participant

    This produced changes, but nothing good. Instead of displaying double it displays correctly, but instead of using the new functions, the only ones displayed is the stock x ones.

    #912351
    Christian
    Moderator

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #978513
    isakfyksen
    Participant
    This reply has been marked as private.
    #978637
    Kleber S
    Participant

    I’m having the same issue. Any luck so far?

    #979301
    Darshana
    Moderator
    This reply has been marked as private.
    #979302
    Darshana
    Moderator

    @kleber

    Would you mind opening up a new thread? so that we can assist you for your specific issues.

    Thanks!

    #981809
    isakfyksen
    Participant
    This reply has been marked as private.
    #981925
    Rad
    Moderator

    Hi there,

    It’s best to execute your customization within the init or wp_head hook with lowest priority. Just like on this thread, https://community.theme.co/forums/topic/any-way-to-override-woocommerce-php-in-child-theme/#post-35185 Or from here https://community.theme.co/forums/topic/changing-size-of-product-image-thumbnail/page/2/

    The idea is, to execute your code last among other codes. It doesn’t matter which hook, as long as it’s executed before woocommerce_shop_loop_item_title.

    I like to test it but I found that you have more complex custom coding that I can’t touch. I may break it further 🙂

    Thanks!

    #982040
    isakfyksen
    Participant

    Feel free to test, I have a backup. Please do notify me of what you do though 🙂

    I have already tried to move it to different priorities, but I don’t see how moving the remove_action statement to a place before the add_action statement would have any effect at all, as there would be no action for it to remove…

    Eureka moment as I was writing this post:

    The remove_action statement does nothing, because x-child/functions.php is executed before the add_action statements in the parent theme files. There are not yet any actions to remove.
    The problem is not that the hook comes to late, its that the statement comes to early.
    What I need to do is to enclose the remove_action statements in a function, and hook it to a hook that comes after the execution of x/framework/functions/global/plugins/woocommerce.php but before the execution of the hooks used in the x/framework/functions/global/plugins/woocommerce.php file (e.g. ‘woocommerce_before_shop_loop_item_title’ and ‘woocommerce_shop_loop_item_title’).

    What hook would you recommend?

    #982647
    Rad
    Moderator

    Hi there,

    I checked and it’s working, the issue is how it’s implemented. For example, on this original code

    function x_woocommerce_shop_product_thumbnails() {
    
      GLOBAL $product;
    
      $id     = get_the_ID();
      $thumb  = 'entry';
      $rating = $product->get_rating_html();
    
      woocommerce_show_product_sale_flash();
      echo '<div class="entry-featured">';
        echo '<a href="' . get_the_permalink() . '">';
          echo get_the_post_thumbnail( $id, $thumb );
          if ( ! empty( $rating ) ) {
            echo '<div class="star-rating-container aggregate">' . $rating . '</div>';
          }
        echo '</a>';
      echo "</div>";
    
    }
    
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
    add_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_shop_product_thumbnails', 10 );
    
    //
    // Shop item wrapper.
    //
    
    function x_woocommerce_before_shop_loop_item() {
      echo '<div class="entry-product">';
    }
    
    function x_woocommerce_after_shop_loop_item() {
      echo '</div>';
    }
    
    function x_woocommerce_before_shop_loop_item_title() {
      echo '<div class="entry-wrap"><header class="entry-header">';
    }
    
    function x_woocommerce_after_shop_loop_item_title() {
      woocommerce_template_loop_add_to_cart();
      echo '</header></div>';
    }
    
    add_action( 'woocommerce_before_shop_loop_item', 'x_woocommerce_before_shop_loop_item', 10 );
    add_action( 'woocommerce_after_shop_loop_item', 'x_woocommerce_after_shop_loop_item', 10 );
    add_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title', 10 );
    add_action( 'woocommerce_after_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title', 10 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

    The woocommerce_before_shop_loop_item_title and woocommerce_after_shop_loop_item_title has added wrappers to wrap the thumbnail. But in your custom code, you use it to output the title with a link. Hence, you’re invoking the links multiple times. I confirmed that by checking the generated HTML source code.

    It’s more on proper implementation of opening and closing bracket. Please follow the structure of original code where it uses wrappers. Like this,

    //
    // Shop product thumbnails.
    //
    
    function x_woocommerce_shop_product_thumbnails_custom() {
    
      GLOBAL $product;
    
      $id     = get_the_ID();
      $thumb  = 'entry';
      $rating = $product->get_rating_html();
    
      woocommerce_show_product_sale_flash();
      echo '<div class="entry-featured">';
        echo '<a href="' . get_the_permalink() . custom_product_query( 'wanted_weight', 'weight' ) . '">';
          echo get_the_post_thumbnail( $id, $thumb );
          if ( ! empty( $rating ) ) {
            echo '<div class="star-rating-container aggregate">' . $rating . '</div>';
          }
        echo '</a>';
      echo "</div>";
    
    }
    
    //
    // Shop item wrapper.
    //
    
    function x_woocommerce_before_shop_loop_item_custom() {
      echo '<div class="entry-product">';
    }
    
    function x_woocommerce_after_shop_loop_item_custom() {
      echo '</div>';
    }
    
    function x_woocommerce_before_shop_loop_item_title_custom() {
      echo '<div class="entry-wrap"><header class="entry-header"><a href="' . get_the_permalink() . custom_product_query( 'wanted_weight', 'weight' ) . '">';
    }
    
    function x_woocommerce_after_shop_loop_item_title_custom() {
      woocommerce_template_loop_add_to_cart();
      echo '</a></header></div>';
    }
    
    add_action( 'wp_head', 'my_custom_woocommerce_hooks' 999 );
    
    function my_custom_woocommerce_hooks () {
    
    	remove_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_shop_product_thumbnails', 10 );
    	add_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_shop_product_thumbnails_custom', 10 );
    
    	remove_action( 'woocommerce_before_shop_loop_item', 'x_woocommerce_before_shop_loop_item', 10 );
    	remove_action( 'woocommerce_after_shop_loop_item', 'x_woocommerce_after_shop_loop_item', 10 );
    	remove_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title', 10 );
    	remove_action( 'woocommerce_after_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title', 10 );
    	
    	add_action( 'woocommerce_before_shop_loop_item', 'x_woocommerce_before_shop_loop_item_custom', 10 );
    	add_action( 'woocommerce_after_shop_loop_item', 'x_woocommerce_after_shop_loop_item_custom', 10 );
    	add_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title_custom', 10 );
    	add_action( 'woocommerce_after_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title_custom', 10 );
    
    }

    Hope that helps.

  • <script> jQuery(function($){ $("#no-reply-910417 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>