WooCommerce shows admin details - wordpress

I've got a problem
Once I go to the checkout page after having added one item or more to my cart, it shows the billing checkout form with already filled inputs. See below:
It shows my full details, including email and phone number to every possible buyer.
I installed the SendGrid plugin and discovered it, but removing the plugin did not fix the issue.
I cannot see in any WordPress option where I can edit the value of these input boxes to be empty.

Super weird...
one thing you can try, is using a hook to alter the current "default" value of your form
Since I don't know, in what priority the default value is already getting changed, I would start by setting it to 20, and then trying 30, 40 etc.
// Hook in -
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields', 20 );
// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'Firstname';
return $address_fields;
}
Hope this works - It was way to long for a comment.

Related

Turn off AutoComplete WooCommerce Checkout Page Form Fields

I want to set the autocomplete to new-password only on the billing address 1 (street address) field so the modern browsers don't give the option to autofill on that field.
Is there a way to do it through a WooCommerce function?
What I have tried so far?
So looking at the output of the woocommerce_checkout_fields, I see the autocomplete is present (see screenshot below). I have tried to change it with the code below but it doesn't work. Maybe I am doing it wrong?
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_address_1']['autocomplete'] = 'new-password';
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
Also, I found this on Woocommerce - Turn Off Autocomplete in Checkout Fields via "autocomplete=new-password" where all fields have been set to new-password, but I don't think it's a nice solution (it changes all the fields).
Thanks to Vijay's comment I started to investigate what could be the cause of the issue. Found out my code works, it was the address autocompletion JS added by Google Places API that's setting the autocomplete attribute to off.
I will contact Google Developer Console support to see if there's a way to mitigate this.

How to properly initialize Woocommerce Cart

I have a custom template file, rendering some products and their Add To Cart buttons, that I am trying to implement manually. When Add to Cart is pressed, the page is reloaded and a $_POST variable containing some data adds the new products. 'cart_contents_count' also reflects the added item. However, when I go to the cart page, it's empty. Please see the following code.
global $woocommerce;
if ( isset( $_POST['AddedToCart'] ) ) {
$woocommerce->cart->add_to_cart($_POST['event'], $_POST['qty']);
}
$cart_total = $woocommerce->cart->cart_contents_count;
When I however go to the normal default shop page ( /shop/ ) and add a product from there, my cart page indicates that this product has been added. When I NOW go to my custom page and add products from that Add To Cart button, it works perfectly.
It seems to me that, before I run the above-mentioned code, I must check if a Cart Session has been initialized, and if not, initialize it. Could someone please confirm for me that I understand it right and show me how to initialize the cart?
Here is a solution if your custom form is on a page template. This code goes in your functions.php file. Be sure to change yourtheme_template to something more unique. Also, change the items in the $session_templates array to the template filenames where you want this filter to be used. It uses the template_include filter, which isn't an easy filter to track down, let alone $woocommerce->session->set_customer_session_cookie(true) - Special thanks to #vrazer (on twitter) for the help.
function yourtheme_template($template) {
//List of template file names that require WooCommerce session creation
$session_templates = array(
'page-template-file-name.php', 'another-page-template-filename.php'
);
//Split up the template path into parts so the template file name can be retrieved
$parts = explode('/', $template);
//Check the template file name against the session_templates list and instantiate the session if the
//template is in the list and the user is not already logged in. If the session already exists from
//having created a cart, WooCommerce will not destroy the active session
if (in_array($parts[count($parts) - 1], $session_templates) && !is_user_logged_in()) {
global $woocommerce;
$woocommerce->session->set_customer_session_cookie(true);
}
return $template;
}
//Filter to run the WooCommerce conditional session instantiation code
add_filter('template_include', 'yourtheme_template');
I resolved this problem by making sure the $woocommerce->cart->add_to_cart() line is positioned before any headers are sent. I.E, before get_header() is called on my custom template.
In the WooCommerce version 2.5 they change the way the sessions works. https://woocommerce.wordpress.com/2015/10/07/new-session-handler-in-2-5/
What i did was install this plugin https://github.com/kloon/woocommerce-large-sessions then my cart is not empty any more with guess users.
I hope it helps someone else.

wordpress plugin hooks method

I am creating a plugin for wordpress.I need database interaction.So i need to run some queries to create table.I want to run those queries in a php function.I need to run this function when this plugin will active.What hooks should i use for this purpose?? Now i am using this:
add_action( 'admin_menu', 'bs_check_database_creation' );
This is working fine so far.But i need appropriate hooks to run this function once when this plugin will activate.
Another queries : i want add a link of this plugin in header/footer/sidebar for end user to go to the plugin end user page.How should i do this?
Currently i've manually added a link for this in wordpress template page.
Thanks in advance
It depends when you want the hook to run, But I think that init or admin_init will be right for you becasue they are the earliest ones running respectively on front and back end.
EDIT : (After comment) The INIT and admin_init are ment to use whenever a plugin needs to RUN, and not on first activation (or install) . writing "I need to run this function when this plugin will active " is a bit confusing :-) active means when it start to run , or when it is actually ACTIVATED ?
If you need to run a function upon ACTIVATION , then it is a bit different..
register_activation_hook(__FILE__, 'o99_brsa_on_activate');
function o99_brsa_on_activate() {
// do your stuff on activation
}
About the links, I am not sure what you mean by end user page ... Do you mean action links ?
And what footer do you mean ? the Admin or the Front ? ( After answering those issues I can try and reply - Even if it is a material for another question .)
As for links in the header / footer . If ou are planning to host this plugin in the wordpress repository please know that it is somewhat against the terms ( unless you request specific permission from the user )
Anyhow , this will do :
function o99_add_to_footer() {
echo '<p>This is inserted at the bottom</p>';
}
add_action('wp_footer', ' o99_add_to_footer');

WooCommerce Show Payment Gateways for Logged In Customers Only

I am setting up an ecommerce site using Wordpress and WooCommerce. We are using the wordpress member accounts to track customer information, and we need a way for logged in members only to be able to choose to purchase their cart "on credit", meaning no payment is required to place the order. Basically what I have done is hi-jacked the "Check" option (since we don't need it anywhere else) and renamed it "Credit" since it allows for the functionality we need.
However, I need a way for the "Credit" (check) option to only display if the user is logged in. Is there any way I can just "unhook" this option if the user isn't logged in? This seems like something that would be easy to do, but I couldn't find anything about it. Any help is appreciated.
The original answer to this question (from BWDesign) no longer works due to changes in WooCommerce (at least from WooCommerce 2.1.7 onwards, possibly before). This does the trick now (tested on 2.1.7 and 2.1.8), add it to e.g. your functions.php file:
add_filter( "woocommerce_available_payment_gateways", "rp_filter_gateways", 9999 );
function rp_filter_gateways($args) {
if(!is_user_logged_in() && isset($args['cheque'])) {
unset($args['cheque']);
}
return $args;
}
I just found the solution. In the class-wc-cheque.php file, the check or "cheque" (crazy brits) option is hooked using add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );. So the solution was simply to add this code to my functions.php file:
if(!is_user_logged_in()){
remove_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );
}
Hope this helps!

WordPress Thesis theme - hook below post

i need a little help with thesis theme, i made a simple hook for single post with custom content and i want the hook to be right after the post but after the post there's a plugins like facebook etc... and my hook is below that. How to make my hook to be right after post without disabling this plugins ?
*i already tried every posible combinations thesis_hook_after_post, thesis_hook_after_post_box etc and it dont work
Thanks in advance !
Change priority value in add_action
add_action( $tag, $function_to_add, $priority, $accepted_args );
(int) (optional) Used to specify the order in which the functions
associated with a particular action are executed. Lower numbers
correspond with earlier execution, and functions with the same
priority are executed in the order in which they were added to the
action. Default: 10
Edit:-
function post_article111() {
if (is_single( )) {
echo "content goes here..";
}
}
add_action('thesis_hook_after_post_box', 'post_article111','5');

Resources