• Thanks to Agus Mu + Mike Jolley and sorry about the initial rating.

    Pocket Flan
    The most delicious flans in the galaxy ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    I don’t see how this has anything to do with WC updates. WC only uses CORE WP FUNCTIONS to register taxonomies. Maybe your code is just bad – you can change labels easily enough using:

    1. A localisation
    2. The filters WE PROVIDE, not the hacky solution above
    3. https://www.ads-software.com/plugins/say-what/ plugin

    Take your pick ??

    Thread Starter Pocket Flan

    (@pocket-flan)

    You could be right (or wrong), and thanks for the suggestions though.

    1) The above warning message popped when I updated Woocommerce.

    2) The code was there BEFORE, and I had updated Woocommerce and WordPress on several occasions, and never had any issue with the above code.

    3) So it seems the Woocommerce update “read” my functions.php file, and gave the warning / deciding that the code wasn’t “good enough”?

    What’s the filter YOU PROVIDE then? I googled “how to rename Woocommerce Product Categories and Woocommerce Product Tags / Mike Jolley” and could not find the answer. Please show to me me or it didn’t happen.

    Off topic: So I read Coen Jacobs’ left! What a shame, he is/was a GREAT man. I have dealt with him before. Very honourable man. Wish him all the best. He deserves it.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    The entire post category registration function is wrapped with a filter: woocommerce_taxonomy_args_product_cat

    https://github.com/woothemes/woocommerce/blob/v2.1.11/includes/class-wc-post-types.php#L52

    That would be the best filter to use if using code. No WP globals needed.

    Using say-what would be just as effective though, and not require any code changes.

    Thread Starter Pocket Flan

    (@pocket-flan)

    And what does the final code would look like?

    As far as I am concerned the above always worked fine, until recently when I updated to the latest version of Woocommerce and got the warning.

    And you claim that the warning message has got nothing to do with Woocommerce.
    Very strange… there must a ghost in the machine then.

    Thanks, but I’d rather not use another plugin for such a small tweak, it’s overkill IMO.

    So there we go, the code used to work… updated Woocommerce and got a warning, you tell me it’s not Woocommerce and I should use a plugin or a filter.

    Please show me the full code?

    I pasted a fully working piece of code. You have got a better one I think, since you have built Woocommerce, please help.

    Thank you.

    @pocket Flan,

    I see two points in your code above.

    1) the code above works only when WooCommerce is active when product_cat taxonomy is active. When you update your WooCommerce, the plugin will be deactivated by WordPress for updating purpose, and this code will trigger an error/warning.

    2) The specific error that you get above comes from PHP5.4. If you use shared hosting, it could be your hosting update PHP version in the server and then produce this error. Please do check with your hosting.

    I second Mike that the code is not “perfect” in this situation and it is not related with WooCommerce. There are two ways to solve it.

    1) you can update your code and check if product_cat taxonomy is active. For example,

    add_action( 'init', 'custom_wc_product_cat_label' );
    function custom_wc_product_cat_label() {
        global $wp_taxonomies;
    
        if ( isset( $wp_taxonomies['product_cat'] ) ) {
    	    $cat = $wp_taxonomies['product_cat'];
    	    $cat->label = 'My Categories';
    	    $cat->labels->singular_name = 'My Category';
    	    $cat->labels->name = $cat->label;
    	    $cat->labels->menu_name = $cat->label;
    	}
    
    }

    2) You can use WooCommerce filter that Mike provided. For example

    add_filter( 'woocommerce_taxonomy_args_product_cat', 'custom_wc_taxonomy_args_product_cat' );
    function custom_wc_taxonomy_args_product_cat( $args ) {
    	$args['label'] = __( 'Product Categories', 'woocommerce' );
    	$args['labels'] = array(
            'name' 				=> __( 'Product Categories', 'woocommerce' ),
            'singular_name' 	=> __( 'Product Category', 'woocommerce' ),
            'menu_name'			=> _x( 'Categories', 'Admin menu name', 'woocommerce' ),
            'search_items' 		=> __( 'Search Product Categories', 'woocommerce' ),
            'all_items' 		=> __( 'All Product Categories', 'woocommerce' ),
            'parent_item' 		=> __( 'Parent Product Category', 'woocommerce' ),
            'parent_item_colon' => __( 'Parent Product Category:', 'woocommerce' ),
            'edit_item' 		=> __( 'Edit Product Category', 'woocommerce' ),
            'update_item' 		=> __( 'Update Product Category', 'woocommerce' ),
            'add_new_item' 		=> __( 'Add New Product Category', 'woocommerce' ),
            'new_item_name' 	=> __( 'New Product Category Name', 'woocommerce' )
    	);
    
    	return $args;
    }
    Thread Starter Pocket Flan

    (@pocket-flan)

    Hi Agus,

    Thanks a lot for you constructive reply and help, very much appreciated.

    Yes, actually PHP was recently upgraded on the server, well spotted!, what you said makes greater sense to me now. I can see you know what you are talking about, and you pointed something very interesting. Thanks for sharing your knowledge.

    On a side note I always thought that an option to rename product tags and categories should have been part of Woocommerce already. It’s obvious, someone who sells food might want to rename it “Food Categories” and so on. Tags could be renamed “Spices, Herbs or Fruits…” etc.

    So, can you please tell me the pros and cons of using option 1) VS 2) if any?
    I Like 1) because it’s shorter and in my book shorter code = usually better, if it achieves the same?

    Thank you again Agus

    From your experience, it is clearly to see that option 2) is better for you because it is designed for WooCommerce only.

    The full idea of adding all labels is, you can change not only the menu name but also all related labels to make it consistent. You only need to change all “Product Categories” and “Product Category” to your custom name. But, if you only need to change the menu label, then I simplify it for you.

    add_filter( 'woocommerce_taxonomy_args_product_cat', 'custom_wc_taxonomy_label_product_cat' );
    function custom_wc_taxonomy_label_product_cat( $args ) {
    	$args['label'] = 'My Categories';
    	$args['labels'] = array(
            'name' => 'My Categories',
            'singular_name' => 'My Categories',
            'menu_name' => 'My Categories'
    	);
    
    	return $args;
    }
    Thread Starter Pocket Flan

    (@pocket-flan)

    Thanks again Agus, I really appreciate your help.

    You also solved a big mystery and explained it very well, regarding the PHP error, which was driving me crazy!

    @mikejolley, you were right, even though you didn’t manage to explain why this was happening ?? In the then it turns out well, thanks for pointing to the filter.

    Thanks again Agus and Mike.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘MYSTERY SOLVED (WAS: Creating default object from empty value…)’ is closed to new replies.