How to access company name from calculate_shipping in WooCommerce? - woocommerce

We need to access the company name from the checkout form in WooCommerce, inside the calculate_shipping (from Shipping Method API) when calculating the shipping options, but it only seems to have the array $package available which in turn just have access to a stripped down version of the $package['destination'] address fields. There is no $package['destination']['company'].
The company name form field in checkout
As part of the Billing address;
<input type="text" class="input-text " name="billing_company" id="billing_company" placeholder="" value="" autocomplete="organization">
As part of the Shipping address;
<input type="text" class="input-text " name="shipping_company" id="shipping_company" placeholder="" value="" autocomplete="organization">
Is there a way to directly access what is entered into the "shipping_company" or "billing_company" textfields or by any other means know if the customer is a company or private person?
I've tried WC()->checkout->get_value( 'shipping_company' ) but that doesn't return the text and there is no $_POST['shipping_company'] or $_POST['billing_company'] despite the AJAX hook when changing address details.

Related

Display in woocommerce order management page custom made <input fields> for shipping methods

I have created the following code which I have added to the PHP function to create two input fields placed just below the fixed-rate shipping method on the check out page. In these two input fields customers can enter their shipping provider and account number.
The input fields work perfectly, the problem is that when the order is placed, the values entered (shipping provider name and account number) in these two fields do not appear in the order details on woocommerce.
Can you please advise me how I can make the two fields appear on the woocommerce order management page so that I know what customers have entered?
code:
function checkout_shipping_additional_field( $method, $index )
{
if( $method->get_id() == 'flat_rate:35' ){
echo '<br>
<input type="text" id="Name" name="Name" placeholder="Shipping Provider">
<input type="text" id="Name" name="Name" placeholder="Account Number">';
}
}

Wordpress Submit hidden input data as custom field (Payment Plugin)

So, I got a payment plugin where some information is entered in an popup.
The popup stores the input data in a hidden input on the payment page
In payments field I got this for the hidden input:
<input type="hidden" class="" name="auth" id="auth" placeholder="" value="">
Via JS I put the value from the popup to the input hidden data, which definetly works!
Then I add an action:
add_action( 'woocommerce_checkout_update_order_meta', 'ccp_payment_update_order_meta' );
function ccp_payment_update_order_meta( $order_id ) {
update_post_data( $order_id, 'auth', sanitize_text_field($POST['auth']) );
}
Somehow after the submission of the checkout form the data ($POST['auth']) is empty.
Why is this happening?
How can I store the value right?
Got it sorted out. It need to be in an paragraph like that
<p class="form-row form-row-wide"><input type="hidden" ...></p>

Associative Arrays in #requestparam

I am completely new to spring mvc. Please excuse me if this is asked already
Problem
A user can have multiple contact details. Each contact detail will have it's own form. For eg phone number -> 1 text box; address -> 3 text boxes
In PHP I used to do
<input type="text" name="contact[0][type]" value="PHONE">
<input type="text" name="contact[0][number]" value="456">
<input type="text" name="contact[1][type]" value="ADDRESS">
<input type="text" name="contact[1][address1]">
<input type="text" name="contact[1][address2]">
<input type="text" name="contact[1][address3]">
and my $_POST array will contain everything formatted into different associative arrays.
Can I do something similar in Spring ?
Update
I been on this for a couple of days and I have tried a few things including List, Map, Properties. I have also modified the name of the input fields. No luck.
For the domain Objects I successfully did the following
class User {
//..
Set<ContactDetails> details;
}
abstract ContactDetails{}
class Phone extends ContactDetails {}
class Address extends ContactDetails {}
Any help would be appreciated.

Creating wp plugin for external login => post comments

I need to create a wordpress plugin to connect wordpress to a central login. But all I want is the user to be able to post comments with name and email filled. I don't think I need create a real loggin into wordpress because the user should not be able to write posts or do admin stuff. I want him only to post comments.
I search the documentation but could not find any action for comments.
How can I change the html of a comment form?
Maybe not good but it works...
Fill comment author and email from central login stored in session:
function portal_user_comment()
{
$_POST['author'] = $_SESSION['portal']['name'];
$_POST['email'] = $_SESSION['portal']['email'];
}
add_action('pre_comment_on_post', 'portal_user_comment');
Edit comments.php from the template. Look for:
<input type="text" name="author" id="author" value="<?php $comment_author; ?>" ...>
<input type="text" name="email" id="email" value="<?php $comment_author_email; ?>" ...>
Set both fields disabled="true" and replace the values with the author and email from the session.

WordPress: Disable add custom field

I allow a guest to post on my WordPress site. I disabled some fields, but I let the user select only one field.
Cool, but he can edit this field.
Example: Field: name.
After I added it, he can rename the field to name2.
So, how do I can a disable this?
Use the readonly attribute,
<input type="text" name="test" value="<?php echo $name ?>" readonly="readonly">

Resources