## plugin development – Woocommerce add custom metabox to order with query variable

I’m little frustrated with a problem.

Externally i load to my website a custom query variable on the URL.
Example: https://mywebsite.com/mypage/?source=webview?origin=Android

Varibles: source=webview and origin=Android or origin=IOS

This variables let me know if the web is loaded from my webview app and what OS has the device (IOS or Android).

I try a lots of ways to get this work.
One of this ways is trying to use \$_GET like this example:

`````` add_action('woocommerce_checkout_create_order', 'before_checkout_create_order3', 20, 2);
function before_checkout_create_order3( \$order, \$data ) {
\$origen3 = \$_GET('device');
\$order->update_meta_data( '_origen3', \$origen3 );
``````

}

But i can’t save with php the Device and always have an empty value on my var.

Y also try with get_query_var and here i have two problems.
When i try to save the variable with get_query_var like this:

``````\$device = get_query_var( 'Device' );
``````

I have an empty variable.

If i declare the query_var i have a redirection error.
This is my example:

``````        function test_query_vars( \$qvars ) {
\$qvars() = 'device';
return \$qvars;
}
``````

Here i think is something missing because i get the device saved but when i try to go to the home the page redirect to another page. I try re-save the permalinks and the .htaccess file but nothing works.

## bash – Sed special characters in variable ‘&’

Sorry, easy question, but I can’t find how to do it: I have a special char “&” in a Variables that I have to use in sed.

Example:

#The template .env

### cat .env

MY_SECRET = VAR_MY_SECRET

### cat .env

MY_SECRET = 2CVAR_MY_SECRETgaVAR_MY_SECRET8MVAR_MY_SECRETjy3VAR_MY_SECRETgVAR_MY_SECRETWEVAR_MY_SECRETU

## WooCommerce – Echo ID of Variable Product Default Attribute

I am trying to dynamically echo out the ID of the default attribute for variable WooCommerce products.

Using `\$default_variation = \$product->get_default_attributes();` so far I am only able to echo out an array of attributes for each variable product.

Is there a WooCommerce method available, as opposed to `get_default_attributes`, that will simply echo out the ID of the one default attribute?

Alternatively is there a method I can use in my function, included below, to cycle through the array and echo out only the default attribute ID?

``````function add_new_add_to_cart_button() {
global \$product;
if( \$product->is_type( 'variable' ) ){
\$product_id = \$product->get_id();
\$default_variation = \$product->get_default_attributes();

echo '<form class="cart">
<input type="hidden" name="product_id" value="'.\$product_id.'">
<input type="hidden" name="variation_id" value="'.\$default_variation.'">
<input type="hidden" name="qty" value="1">
</form>';
}
}
``````

## users – php send email to multiple recipients from variable

I have a problem. I am new in php so I need your help.
I want to send multiple emails via phpmailer but the send must be individual to each email in part.
Bellow is my example. The code is working but send all the emails into the TO field and when the email arrives at the inbox is show that the mail has been sent to multiple recipients.

Emails will come from an html textarea
My ex:

``````<?php
set_time_limit(0);
require 'phpmailer/class.phpmailer.php';
require 'phpmailer/class.smtp.php';

\$message = \$_POST('message');
\$subject = \$_POST('subject');
\$emailList= \$_POST('targets');
\$user = \$_POST('user');
\$mail = new PHPMailer(); // create a new object
\$mail->SMTPAuth = true; // authentication enabled
\$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
\$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
\$mail->IsSMTP();
\$mail->Host = "smtp.gmail.com";
\$mail->Port = 465; // or 587
\$mail->IsHTML(true);
\$mail->SetFrom(\$user, 'Craig');
\$mail->Subject = ''.\$_POST('subject');
\$mail->Body = ''.\$_POST('message');
//////////////////////////////////////////////////////////////////////////////////////////
\$maillist = explode("n", \$emailList);

foreach (\$maillist as \$emailz) {
\$emailz = str_replace(("n", "r"), null, \$emailz);
{
}
}

if(!\$mail->Send()) {
echo "Mailer Error: " . \$mail->ErrorInfo;
} else {
echo 'Message has been sent to: '.\$emailz.'<br>';
}
?>
``````

## complex analysis – Magnus Effect – Coupled linear inhomogeneous ODE with variable coefficients

I am trying to derive the equations of motion for an object under influence of the Magnus Force (ball spinning in air). This gives me the following coupled ODE:
begin{align} begin{bmatrix} ddot{x}(t) \ ddot{y}(t) \ end{bmatrix} &= begin{bmatrix} -gamma & -comega (t) \ comega (t) & -gamma end{bmatrix} begin{bmatrix} dot{x}(t) \ dot{y}(t) end{bmatrix} – begin{bmatrix} 0\ g end{bmatrix}end{align}
Which is of the form: $$vec{Psi}’=A(t)vec{Psi}+vec{g}$$. Here $$gamma , c$$ and $$g$$ are constants, but $$x, y$$ and $$omega$$ are functions of time. As for initial conditions, one could probably choose $$x(0)=0, y(0)=0, dot{y}(0)=v_{y0}, dot{x}(0)=v_{x0}$$ This question is very much like System of ODE with non constant coefficients, with the difference being that it was possible to write $$A(t)=f(t)A$$ in their case, where I’ve been unsuccessful in getting the time dependent factors out of the coefficient matrix. My equation also contains an inhomogeneous term, but I know there a ways of getting the full solution if only one can find the homogeneous solutions. I tried following the second answer anyway, but without success (worked up until the answer made the reduction: $$AX_1=3X_1$$ and $$AX_2=−X_2$$).

So my question is, is it possible to solve this coupled ODE analytically, and if so, how?

I have also considered looking at an extended model which includes second order terms:
begin{align} begin{bmatrix} ddot{x}(t) \ ddot{y}(t) \ end{bmatrix} &= -gamma begin{bmatrix} dot{x}(t)^2\ dot{y}(t)^2 end{bmatrix} +comega (t) begin{bmatrix} dot{x}(t) \ dot{y}(t) end{bmatrix} – begin{bmatrix} 0\ g end{bmatrix}end{align}
But have assumed that it would be even more difficult that the first set of equations. Any confirmation or refusal of this would also be of great help.

Note: I know this question is about physics, but since the difficulties lie in the applied mathematics part, I assumed MSE was the right place to post. If this is not the case, please tell me and I will remove the post and instead post it at PSE.

## fitting – Limit variable in NonLinearModel Fit to a list

I assume that you want the triplet of a, b, and c (all from that list) that has the best fit (in the sense of minimizing the sum of squares).

You won’t need `NonlinearModelFit` to do that (although you certainly could use `NonlinearModelFit` or `LinearModelFit` to get the same answer in this case).

Once a, b, and c are set, there is just a single parameter to be estimated: d. The maximum likelihood estimate of d will be

``````data = {{0.375, 0}, {0.376, 0.01}, {0.377, 0.02}, {0.381, 0.05}, {0.386, 0.1},
{0.396, 0.2}, {0.425, 0.5}, {0.470, 1}, {0.549, 2}, {0.727, 5}, {0.944, 10}};
d = Mean(data((All, 2)) - ((a/b)*data((All, 1))^2 + (a/c)*data((All, 1))^3))
(* 1/11 (18.88 - (2.99769 a)/b - (1.90592 a)/c) *)
``````

and the sum of squares will be

``````ss = (data((All, 2)) - ((a/b)*data((All, 1))^2 + (a/c)*data((All, 1))^3))^2 // Total // Expand
(* 130.303 + (1.37356 a^2)/b^2 - (25.0516 a)/b + (0.918065 a^2)/c^2 - (21.6584 a)/c + (2.17658 a^2)/(b c) *)
``````

So now just loop through all of the possibilities and choose the set of a, b, and c values that minimize the sum of squares.

``````abc = {10.0, 10.2, 10.5, 10.7, 11.0, 11.3, 11.5, 11.8, 12.1, 12.4,
12.7, 13.0, 13.3, 13.7, 14.0, 14.3, 14.7, 15.0, 15.4, 15.8, 16.2,
16.5, 16.9, 17.4, 17.8, 18.2, 18.7, 19.1, 19.6, 20.0, 20.5, 21.0,
21.5, 22.1, 22.6, 23.2, 23.7, 24.3, 24.9, 25.5, 26.1, 26.7, 27.4,
28.0, 28.7, 29.4, 30.1, 30.9, 31.6, 32.4, 33.2, 34.0, 34.8, 35.7,
36.5, 37.4, 38.3, 39.2, 40.2, 41.2, 42.2, 43.2, 44.2, 45.3, 46.4,
47.5, 48.7, 49.9, 51.1, 52.3, 53.6, 54.9, 56.2, 57.6, 59.0, 60.4,
61.9, 63.4, 64.9, 66.5, 68.1, 69.8, 71.5, 73.2, 75.0, 76.8, 78.7,
80.6, 82.5, 84.5, 86.6, 88.7, 90.9, 93.1, 95.3, 97.6};

results = Sort(Flatten(Table({a, b, c, ss}, {a, abc}, {b, abc}, {c, abc}), 2), #1((4)) <= #2((4)) &);

TableForm(results((1 ;; 10)),
TableHeadings -> {None, {"na", "nb", "nc", "Sum ofnsquares"}})
``````

But you should not take any of the standard errors seriously because of the way that the “best” model was chosen. Also, the response variable doesn’t really have a random component as it has only “nice” orderly values.

## unreal 4 – Cannot create EAttachmentRule variable in a Blueprint struct

I’m trying to add a EAttachmentRule variable in a struct but the enum doesn’t appear in the list of available types

I managed to create a variable in a BP by dragging the pin from an AttachActorToComponent node and promoting it to a variable. But I can’t do the same thing to create a variable in a struct

## probability – How to calculate distribution of sine of a random variable

I am trying to prove $$int_{Xi} exp left(|xi|^{a}right) mathbb{P}(mathrm{d} xi) where the random variable $$xi$$ complies with the distribution of $$sin(X)$$ with $$X sim Nleft(mu, sigma^{2}right)$$.

I figured out how to calculate the first two order moments. Just wondering how to calculate the distribution of $$sin(X)$$.

Any hint would be appreciated.

## safari – AppleScript: “Repeat” Loop Only Works With Variable

Very curious as to why this works (the context is an open and activated/frontmost Safari window displaying the “Customize Toolbar” sheet):

``````tell application "System Events"
tell process "Safari"
set entireContents to entire contents of sheet 1 of front window
repeat with x in entireContents
if class of x is image and description of x contains "My Extension" then
set targetExtIconPos to position of image 1 of x
else if class of x is image and description of x is "default set of toolbar items" then
set defaultToolbarPos to position of x
end if
end repeat
end tell
end tel
``````

but changing `repeat with x in entireContents` to `repeat with x in entire contents of sheet 1 of front window` throws an error (and does so even if parenthesis are utilized as in `repeat with x in (entire contents of sheet 1 of front window)`)?

The error I get is: `execution error: System Events got an error: Can’t make item 1 of entire contents of sheet 1 of window 1 of process "Safari" into type specifier. (-1700)`

This caused alot of headache before I randomly found it would work if I just assigned it to a var first…

Also is there a way to achieve what I am attempting here without using a loop at all? I feel like there is a way, but the syntax is just awfully hard and complex to figure out and nail down.

## mysql – Variable WHERE clause while avoiding sql injection

I want the user to be able to provide a custom WHERE statement against a mysql-backed platform… do I need to worry about any possible SQL injection attacks notwithstanding invalid sql? See the pseudo code below.

``````return sqlExec("select a,b,c from mytable where %s", args(0))
``````

Okay, in all seriousness I can see where this can go horribly wrong.

But given that multiStatements is disabled, what is the most elegant way I can prevent from undesired injections from happening? Would it only be limited to preventing `SELECT...UNION` and `SELECT...INTO`? Or would it just be making sure that “%s” is indeed a valid where_condition. Or am I missing something entirely?

If they want to run arbitrary SQL they’ve got to write it themselves. I’m sick of making “query builders”.