My Courses > CustomizeWoo > Module 5 > Lesson 05: How to Edit EVERYTHING

How to Edit EVERYTHING

MARK LESSON AS COMPLETE

Now customization gets tougher, but don’t worry. A quick file search through the WooCommerce plugin files can help you immensely.

Video

Please note: English captions are enabled by default (click on “CC” in the video player to disable). Also, you can click on the “gear” icon to manage quality and playback speed. Enjoy!

Sorry, this video is only visible to logged in Business Bloomer Club members with a PRO PASS.
If you joined already, please log in.
Otherwise, here is why you should join the Club.

17 thoughts on “How to Edit EVERYTHING

  1. Hi, In the second half of the video the words “may also” are used as the search term
    there is an apply_filters in the up-sells.php

    the only way I could get it to work with apply filters was to delete everything in the brackets. If I use $heading, $product in the brackets and any other combinations, it doesn’t work.

    Am I missing something?

    If I remove them from the function change cart label, it still works as well.
    I am using flatsome theme if that is of use.

    // apply_filters( 'woocommerce_product_single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $this );
    
    add_filter ( 'woocommerce_product_single_add_to_cart_text', 'fred_change_cart_label', 9999, 2 );
    
    function fred_change_cart_label ( $label, $product ) {
    	$label = "Don't Miss This Bargain";
    	return $label;
    }
    
    // $heading = apply_filters( 'woocommerce_product_upsells_products_heading', __( 'You may also like…', 'woocommerce' ) );
    
    add_filter( 'woocommerce_product_upsells_products_heading', 'fred_change_upsell_heading', 99999, 2 );
    
    function fred_change_upsell_heading( ) {
    	$heading = 'Others also purchased...';
    	return $heading;
    }  
    
    1. Hello there!

      This is wrong:

      add_filter( 'woocommerce_product_upsells_products_heading', 'fred_change_upsell_heading', 99999, 2 );

      And that’s because the filter only comes with 1 parameter, which is the heading itself. If you remove the “2” or change it to “1” (they’re equivalent), it should work

      Let me know

  2. Hello,
    How could I change the product tags order in the single product page, so they do not appear alphabetically? Thank you!

    1. Hi Marcel!

      Here’s how I’d roll:

      • You look for the template that prints the tags – it’s “meta.php” under “/single-product”
      • You find the wc_get_product_tag_list() function
      • You search for this function inside WooCommerce
      • You find this line: return get_the_term_list( $product_id, ‘product_tag’, $before, $sep, $after );
      • You search for get_the_term_list() in WordPress
      • You find https://developer.wordpress.org/reference/functions/get_the_term_list/
      • And finally, you see there is a filter: “term_links-{$taxonomy}” that you can use in your customization

      Hope this helps!

  3. Hello Rudolfo,
    Please give me a direction on how could I implement, on the reviews area, the possibility that customers to upload images with products they bought, and the images uploaded to appear on the website. I know there are some plugins for this, but I would prefer to code it manually. Thank you!

    1. Hey Marcel! That’s quite complex, but let’s see if I can give you a possible strategy.

      1) First of all I go looking for the code responsible to output the comment/review form. I search for “comment-form-comment” inside WooCommerce plugin and find only one result under woocommerce\templates\single-product-reviews.php

      2) I’m now in the correct file, and will go looking for filters, to see if the system allows me to alter the comment form. On line 136 I find this:

      comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );

      so before giving the form to the website, I can edit the comment form args

      3) Now I move back up to see if there is an “arg” that is responsible to add comment fields. Indeed, there is

      $comment_form['fields'][ $key ]

      , where each “key” is the one of a contact form field i.e. the stars rating, the comment textarea, the subscription checkbox

      4) This means I can add a custom form field! So I will write an

      add_filter

      function that adds another element to $comment_form[‘fields’], and you can call it $comment_form[‘fields’][‘image_upload’] or something. Then, you return $comments back to the website

      5) At this stage, the only thing remaining is figuring out how to create a file upload input form field. Here’s an example: https://businessbloomer.com/woocommerce-file-upload-my-account-registration-form/

      Good luck!

  4. Hi, it’s me again… I see that a filter for the related products heading was introduced last month. I wrote the following code to edit it.

    add_filter( 'woocommerce_product_related_products_heading', 'edit_related_products_heading', 10, 2 );
    function edit_related_products_heading( $label, $woopage ) {
        $label = 'Pairs well with';
        return $label;
    }

    But I get an error that there are too few arguments. But I have two? What have I done wrong here? Thank you for your help as always.

    1. Hello Noelle, thanks for your super useful questions! In this case, I looked for the “woocommerce_product_related_products_heading” and it only comes with one argument (the heading indeed):

      apply_filters( 'woocommerce_product_related_products_heading', __( 'Related products', 'woocommerce' ) )

      You see, there is only one argument that comes with the filter:

      __( 'Related products', 'woocommerce' )

      In your snippet, removing “$woopage” and the “2” would make that work.

  5. Hi Rodolfo, I see that your snippet on https://businessbloomer.com/translate-single-string-woocommerce-wordpress/ has changed. I am trying to understand it (with my limited PHP knowledge). I can see something about not being an admin page, and being a Woo page (if I am correct)… but now what exactly does this mean?

    if ( ! is_admin() && 'woocommerce' === $domain )
    1. Excellent question once again!

      is_admin() is a conditional check to see if the administrator is looking at the WordPress dashboard (https://developer.wordpress.org/reference/functions/is_admin/). Basically, I’m making sure the translation only occurs on the frontend

      $domain is an argument that the filter gives us access to. It’s the “text domain” actually, and it belongs to the internalization of WordPress (https://developer.wordpress.org/themes/functionality/internationalization/). With that check, I’m making sure I’m only translating the WooCommerce plugin string but not the same string (if any exists) if offered by another plugin or theme.

  6. Hi! I am trying to change the message that appears on /my-account/ – I want to remove the “manage your shipping and billing addresses” part as I have removed the /edit-address/ endpoint.

    I have done a folder search and tried to look for apply_filter but couldn’t find anything. I have successfully removed the message and thought I could replace it, but when I try to do so I get an error: “Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘custom_my_account_message’ not found or invalid function name in /wordpress/wp-includes/class-wp-hook.php on line 288”.

    Here is my code:

    remove_action( 'woocommerce_account_content', 'woocommerce_account_content' );
    add_action( 'woocommerce_account_content', 'custom_my_account_message' );
    function custom_my_account_message() {
        echo 'TEST';
    }

    What could cause this error?

    1. Hello Noelle ๐Ÿ™‚

      Here’s the WooCommerce code:

      <p><?php
      	printf(
      		__( 'From your account dashboard you can view your <a href="%1$s">recent orders</a>, manage your <a href="%2$s">shipping and billing addresses</a>, and <a href="%3$s">edit your password and account details</a>.', 'woocommerce' ),
      		esc_url( wc_get_endpoint_url( 'orders' ) ),
      		esc_url( wc_get_endpoint_url( 'edit-address' ) ),
      		esc_url( wc_get_endpoint_url( 'edit-account' ) )
      	);
      ?></p>
      

      As you can see, there is no filter or action – which is very bad. When this happens, it’s great to contact WooCommerce on Github to ask them to add a filter (for the long term) e.g. https://github.com/woocommerce/woocommerce/issues/20744

      For the short term, in this case your goal is to “translate some WooCommerce text” – you should use https://businessbloomer.com/translate-single-string-woocommerce-wordpress/

      Hope this helps!

      1. The string you should use in the snippet is:

        'From your account dashboard you can view your <a href="%1$s">recent orders</a>, manage your <a href="%2$s">shipping and billing addresses</a>, and <a href="%3$s">edit your password and account details</a>.'
        
  7. What if I wanted to change the font of the text as well? How would I do that? Thanks

    1. Hello Paul, so first of all is that a default web safe font (https://www.w3schools.com/cssref/css_websafe_fonts.asp) or a custom Google font?

  8. it all worked like a charm. Very easy to understand and follow and you added advise on how to edit anything with gettext!! Just great, thank you, it has worked perfectly for me,

    add_filter('woocommerce_product_add_to_cart_text', 'shessvy_change_addtocart', 10, 2); 
    
    function shessvy_change_addtocart ( $lable, $product ) {
        $label = 'This can be changed';
        return $label; 
    
    }
    1. Excellent Shessvy!

Questions? Feedback? Support? Leave your comment now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]

Your email address will not be published. Required fields are marked *