Have you had problems with alter/remove/change or add fields for the edit shipping or edit billing addresses? Doing a search on this topic seems like I wasn't the only one who had the problem. But I've the solution for how to do this.
The first problem I had was to to know what function that controlled this fields. But pretty soon I found out that they where in fact described in the woocommerce docs.
The shipping fields exists in this function : woocommerce_shipping_fields and the billing fields exists in this function: woocommerce_billing_fields.
So the method to change these fields are then fairly easy to do. This is an example code in the functions.php-file on how to remove an unnecessary field "shipping state" and to set an label to the "shipping address 2":
add_filter( 'woocommerce_shipping_fields' , 'custom_override_shipping_fields' );
function custom_override_shipping_fields( $fields ) {
unset($fields['shipping_state']);
$fields['shipping_address_2']['label'] = 'Address Field 2';
return $fields;
}
The same solution goes for billing fields.
If you want to alter any fields on the checkout page you could use this method also. The function for those fields lays in this function "woocommerce_checkout_fields". An heads up: the array $fields is one step deeper and therefore if you want to remove the shipping_state like in the example above then you would need to to it like this: "unset($fields['shipping']['shipping_state']);" - notice the extra bracket.
If you would like to know which fields exist for e.g. the shipping fields function, then use the php function var_dump(). IE: Put "var_dump($fields)" inside the custom override function and it will show you how the array looks like and all the settings for all fields.
Friday, October 4, 2013
Tuesday, January 15, 2013
Config logrotate for apache log-files in "www"-directory or in other non-standard
If you have configured Apache to split error and access logs for each virtual server or configured website. Then logrotate wont rotate those log-files in their custom locations with standard configs. Logrotate comes normally installed with your distribution and is configured to rotate the apache log files that is located in /var/logs/apache2.
But if you have several websites running on your VPS or server, it's linkley you have a seperate log file for each website that you have configured and the logging wont be in the standard location.
As an example. I've several websites running under a structure of "/var/www/$NAMEOFTHEWEBSITE". Now each website has separate logging, in a structure like this "/var/www/$NAMEOFTHEWEBSITE/logs". In each logs-directory I've a access.log, error.log and a php-error.log. If I want to rotate these with logrotate I need to configure logrotate for that.
This is done by creating another config file for my custom directories.
Then with this configuration:
My configuration does this:
But if you have several websites running on your VPS or server, it's linkley you have a seperate log file for each website that you have configured and the logging wont be in the standard location.
As an example. I've several websites running under a structure of "/var/www/$NAMEOFTHEWEBSITE". Now each website has separate logging, in a structure like this "/var/www/$NAMEOFTHEWEBSITE/logs". In each logs-directory I've a access.log, error.log and a php-error.log. If I want to rotate these with logrotate I need to configure logrotate for that.
This is done by creating another config file for my custom directories.
vim /etc/logrotate.d/www
Then with this configuration:
/var/www/*/logs/*.log {
weekly
missingok
rotate 26
compress
delaycompress
dateext
notifempty
create 640 root adm
sharedscripts
postrotate
if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ];
then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
}
My configuration does this:
- For each and any .log-file in /var/www/*/logs/
- Do weekly rotation. (weekly)
- If log-file is missing, ignore without error message (missingok)
- Rotate for 26 weeks (rotate 26)
- Compress all log-files (compress)
- Delay compression with one time (delaycompress)
- Name the rotated files with a date-based name so it's easier for me to know where to look (dateext)
- Do not rotate if log-file is empty (notifempty)
- Owner and permission settings for rotated file (create 640 root adm)
- Normally, prescript and postscript scripts are run for each log which is rotated, meaning that a single script may be run multiple times for log file entries which match multiple files (such as the /var/log/news/* example). If sharedscript is specified, the scripts are only run once, no matter how many logs match the wildcarded pattern. However, if none of the logs in the pattern require rotating, the scripts will not be run at all. This option overrides the nosharedscripts option and implies create option. (sharedscripts)
- The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed after the log file is rotated. These directives may only appear inside of a log file definition. (postrotate & endscript)
That's it. I hope it helps you out configuring your vps or server with the very useful logrotate.
Wednesday, December 5, 2012
require directives present and no Authoritative handler
If you get an error that looks like this in the Apache error.log:
Then you've probably configured your .htaccess file wrong. As an example, you may have configure the Require user wrong.
If you want to grant access to a singel user then the line in the htaccess-file should look like this:
An example of the whole htaccess with Basic authentication:
Hope it helps you out!
access to / failed, reason: require directives present and no Authoritative handler.
Then you've probably configured your .htaccess file wrong. As an example, you may have configure the Require user wrong.
If you want to grant access to a singel user then the line in the htaccess-file should look like this:
Require user <username>And if you want to grant access to any valid user then it should be like this:
Require valid-user
An example of the whole htaccess with Basic authentication:
AuthUserFile /var/www/.htpasswd
AuthName "Enter Password"
AuthType Basic
Require user admin
Hope it helps you out!
Subscribe to:
Posts (Atom)