Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • damiankaelgreen

    (@damiankaelgreen)

    The documentation provided in the link above worked for me! However, switching from the old way of adding custom fields was originally described in this post was a little difficult for me to grasp at first, even with the documentation.

    So here’s a summary of what I learned, and what I thought was missing from the documentation:

    The old way required three steps to add new fields, the new way only requires one or two, depending on whether or not the custom field value is coming directly from order meta-data (only one step), or if the custom field value is going to be processed further with special programming (two steps).

    If you only need to directly add new order meta-data values, then follow the steps at the top of the documentation How to add custom field to export report? and leave the “not in meta” check boxes blank. Also note that the “field name” can be anything and will be what is written in the header of the .csv file. The “field key” should match the name of the meta-data name…

    If you need to do some post processing on the meta-data, or just want to write your own custom code to generate data for the field, then in addition to adding the field keys to the admin menu by following the first step above (How to add custom field to export report?) you need to check the “not in meta” boxes, and then add your custom code as the documentation suggests under Adding field other than postmeta value. Make sure the “field key” entered in step one matches exactly the term used in the case statement of the wsoe_add_custom_field_to_export function. There is no need to use any of the old hooks and functions besides the new one (you may delete them if you had them in your functions file).

    And if you were adding custom fields the old way, then here’s some additional advice:
    Note that the old examples used $od as a variable that was being passed into the add_action(‘wpg_before_csv_write’, ‘csv_write’, 10, 3); example. Now, in the new example, $od is now being represented as $order_details, thus if you had $od in your old code, you must change it if you are copying it into the case statement. You should also check that you don’t return from a case statement without pushing something on to the $csv_values array or you may end up with missing commas in your .csv (comma separated value) file.

    Note also that you may need to click “save” numerous times throughout the process in order for the reorder fields to show up correctly…

    Also, for new users, I think it would help to see an actual chunk of code that might be inserted in the case statement, so I’m including what I’ve written to add three separate new custom fields here as a complete example:

    add_action('wsoe_addon_add_to_csv', 'wsoe_add_custom_field_to_export', 10, 6 );
    function wsoe_add_custom_field_to_export( &$csv_values, $order_details, $key, $fields, $item_id, $current_item ) {
    
        switch ( $key ) {
    
            case '_DKGs_custom_postcode':
    
                		$order_id = $order_details->id;
    
    			$postcode = get_post_meta( $order_id, '_shipping_postcode', true );
    			if ((trim($postcode) == false)){
    				$postcode = get_post_meta( $order_id, '_billing_postcode', true );
    				if ((trim($postcode) == false)){
    					global $woocommerce;
    					$postcode = $woocommerce->customer->get_shipping_postcode();
        					if ((trim($postcode) == false)){
    						$postcode = $woocommerce->customer->get_postcode();
    					}
    				}		
    
    			}
                array_push( $csv_values, $postcode );
            break;
    
            case '_DKGs_custom_login_name':
            		$order_id = $order_details->id;
    			if( empty( $order_id ) ){
    				$my_username = "Error: no order_id";
    				array_push( $csv_values, $my_username );
    				return '';
    			}
    			/* Guests do not have a user_login name so this code is not as helpful as what follows*/
    				$user_id  = get_post_meta( $order_id, '_customer_user', true );
    				$userobj        = get_user_by( 'id', $user_id );
    				//$display_name = $userobj->display_name;
    				$display_name = $userobj->user_login;
    
                array_push( $csv_values, trim($display_name) );
            break;
    	case '_DKGs_custom_username':
    			$order_id = $order_details->id;
    			if( empty( $order_id ) ){
    				$my_username = "Error: no order_id";
    				array_push( $csv_values, $my_username );
    				return '';
    			}
    
    			$firstname = get_post_meta( $order_id, '_billing_first_name', true );
    			$lastname  = get_post_meta( $order_id, '_billing_last_name', true );
    			$display_name = "";
    			if ((trim($firstname) == false) and (trim($lastname) == false)){
    				$user_id  = get_post_meta( $order_id, '_customer_user', true );
    				$userobj        = get_user_by( 'id', $user_id );
    				$display_name = $userobj->user_login;
    			}
    		$my_username = trim( $firstname.' '. $lastname.' '. $display_name  );
    
    	    array_push( $csv_values, $my_username );
            break;
    
            default:
            break;
    
        }
    }

    One final note, at the time of writing this, I’ve noticed that there is a confusing typo in one of the listed field keys. The field named: “order shopping” prints out the order shipping price, so I expect it is just a typo that should be changed to say: “order shipping”. I bet Ankit will change that soon though…

    Good luck to all, and nice job with this plugin add on Ankit…

    Here’s a reference to a discussion indicating that it is indeed a problem with the Storefront theme and that it has been reported and scheduled to be fixed on the next released update: https://www.ads-software.com/support/topic/problem-with-star-rating-1

    I also am having this issue with the WooTheme: Storefront. I think it hasn’t been updated in many years, but the wooCommerce plugin has. Could that have had something to do with your situation?

    It should be a relatively simple solution to fix with css. If I find it I’ll check back and post my solution here…

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    One more note: “init” is a keyword that also has peculiar behavior. In one testcase, I found it to force the add_action to be called in the child theme <i>after</i> the same function was called in the parent theme. If that word is changed to ‘my_init’ the function is called before the parent theme function. Somewhat counter intuitive, that is…

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    I just wanted to point out, to anyone else who happens to read this though, that wrapping the require_once statements in a function might not work in all situations. In the case which I referenced above (the underlying problem), my solution did not wrap the require statements in a function because wrapping it caused the file and function to be read after the one that was declared by a function in the parent theme, and that caused an fatal error where the function was being declared twice. I’m not exactly sure why the error didn’t occur when the new function was “required” first, outside the wrapping function, but not wrapping it was the only way I found to get it to work in my child theme… Weird…

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    Thanks New Nine,
    Good explanation. Topic resolved!

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    OK, that seems like the kind of thing I was looking for. I still have some questions about that though: Why put the require_once inside a function? Is that to cause the resources to be loaded later?

    Also, Is there a significant reason to use “require_once” instead of just “require” or “include” in a functions.php file?

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    OK, just to provide an update for anyone else who might have to deal with this issue, here’s what I did:

    It turns out all I needed was to override the end_el walker function, which is very short, and in the end, I put the following in a file in my child dir:

    <?php
    class Storefront_child_Walker_Nav_Menu extends Walker_Nav_Menu {
    	public function end_el( &$output, $item, $depth = 0, $args = array() ) {
    	    $output .= "</li><!--\n-->";
    	}
    }

    Then required it in my functions.php file, like so:
    ‘require (‘inc/child_storefront_walker_nav_extension.php’);’ (I could have just added it directly to my functions.php file without putting it in a separate file I suppose…).

    I also then had to locate where the wp_nav_menu function was called in my parent theme, I copied that whole function to another file in my child theme and required it in a similar manner as the file above, and inside that function, I modified the call from this:

    wp_nav_menu(
    				array(
    					'theme_location'	=> 'primary',
    					'container_class'	=> 'primary-navigation',
    					)
    			);

    to this:

    wp_nav_menu(
    				array(
    					'theme_location'	=> 'primary',
    					'container_class'	=> 'primary-navigation',
    					'walker' => new Storefront_child_Walker_Nav_Menu(),
    					)
    			);

    In some cases I think instead of just requiring or including these files, you might need to do something like this in your functions.php file: remove_action('function_that_called_the_wp_nav_menu','function_name'); and then: add_action('new_overridden_function','function_name');

    Anyway, I hope that is descriptive enough to help someone else…

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    Thank you New Nine, I’ll look into writing a new walker class as you suggest.

    Also, I appreciate that you have suggested some other possible alternatives. I’ve already tried floating the items, however, and in order to get that to work with other divs and button elements in the menu, I’d have to modify the html anyway; so might as well fix the “\n\t” problem. (It would be nice if WordPress commented these out in some future release, but I understand that it might cause problems for those who have already added negative margins in their css; and besides, someday, perhaps css4 or 5 will include a white-space-collapse property that will provide another solution to this problem).

    Also, the reason I don’t want to go with the font sizing solution is because it has been suggested that it may have different behaviors in various situations; it just doesn’t seem very solid to me.

    Anyway, rewriting the walker class may not be the easiest solution, but I think it is the right solution and exactly what I’m looking for; so thank you for your direction.

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    New Nine mentioned that:

    anything that doesn’t have a hook could still be included in some way through custom PHP in your theme or a plugin.

    Perhaps, this is what I am talking about. What is the recommended way of doing this?

    Thread Starter damiankaelgreen

    (@damiankaelgreen)

    OK, thank you for your replies.
    If there is a filter or hook for the function I am trying to override, it is not entirely obvious as to how it should be done, because there are no actions or hooks added for the function within the file itself, and I’ve reviewed the entire list of filters, and there are none that pertain to this function specifically.
    I think that if there is a hook to override a file or function, then unless it can be found within the file that contains the function you should expect people to try to override that file. Clearly these cases exist and so it seems that there should be a way to override the file. Not that I’m saying it is wise to do so…

    Anyway, here is a link to the underlying problem I am trying to solve, but I think it is irrelevant to this conversation…

    Also, just another update, I searched for Gabriola in the wp-options database table, which is really the only place I’d expect it to be in the database, and I didn’t find it there either…

    Thanks, but I don’t see any references to Gabriola there. I am using a free theme from GoDaddy called Cleanio, developed by CyberChimps that is not well supported by them, and that complicates the code a little. I’ll try posting the same question on the limited forum that CyberChimps has to offer and post a response here if I get an answer.

    I am having the same problem, but I do not know where the source code is…

    The error I see in chrome is:
    Request URL:https://fonts.googleapis.com/css?family=Gabriola&ver=4.1.1
    Request Method:GET
    Status Code:400 Bad Request

    And it’s true! I’ve found that if I put that url into the browser, I get an error, but if I change Gabriola to Gabriela, then it works. So somewhere, someone created a typo…

    According to the sources tab of the chrome developer tool, the problematic line is in the (index) and the exact line is:
    <<strong>link</strong> rel='stylesheet' id='google-font-css' href='https://fonts.googleapis.com/css?family=Gabriola&ver=4.1.1' type='text/css' media='all' />

    But the problem is that I don’t know where the source of that is coming from… I’ve grep’d the entire directory structure for “Gabriola” and the only place it shows up is in various _index files in the wp-content/cache/page_enhanced/<site_name>/ and …/*/ dirs.

    But I suspect that these cache files are subject to be reconstructed with the theme files, I don’t think I can really modify those…

    There are however several references to googleapis in some of my theme “hooks” dirs, but no where is there a reference to “Gabriola”.

    So where the heck is the source of this word so I can fix it? Could it be in the database somewhere?

    Any suggestions would be welcome…

Viewing 14 replies - 1 through 14 (of 14 total)