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;
}
add_filter( 'query_vars', 'test_query_vars' );

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.

tnks on advice.

javascript – Capturar variable del constructor

Tengo una variable en el constructor llamada f0. Ahora estoy creando otra función la cual necesita dicha variable, pero no puedo sacarla. ¿Cómo podría hacerlo?

constructor(id, idtxt, params){

      let f0 = document.createElement('div');
      f0.innerHTML = tem(3).innerHTML;
      document.getElementById(id).appendChild(f0);

      this.contentForm = f0.querySelector(".content-form");

      this.structure();
   }

   structure(){
      var ff = document.f0.querySelectorAll()
   }

theming – Pass custom variable to block.html.twig

I have a customer who requires the correct set of responsive classes for his block in a given theme depending on its position and count. In my theme_preprocess_page(&$vars) I can identify the blocks in this region and build up an array for each block using its plugin_id and save it to $variables('highlighted').

In my page.html.twig I use {{ highlighted }} and the array shows up wonderfully. Because block.html.twig by default is set up to be looking for {{ plugin_id }} I expected that I can test if plugin_id is in_array() and add these classes to that instance of the block.

But {{ highlighted }} in block.html.twig returns null in this theme, suggesting that $variables('page') works for the page, but not block?
Twig has a way to pass off variables to an arbitrary twig file but I do not know how to do this in Drupal. For instance, my page.html.twig is using {{ highlighted }} to pull in these blocks from $variables.

So my question is how does Drupal 8’s adaptation the Twig source determine which variables are passed (plugin_id, content, attributes, id, etc) and how I can add mine? I’ve looked through the twig.engine and searched the Twig source, but it’s not clear to me which class controls what variables are passed to blocks?
My other avenue is to find a way to pass this array of classes to theme_preprocess_block but every attempt I made to try this ends up with theme_preprocess_block returning NULL for this array, suggesting that preprocess_page() and preprocess_block() are working separtely.

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">
        <button class="button product_type_variable add_to_cart_button" style="float:none;" type="submit" name="add-to-cart" value="'.$product_id.'">Buy Now</button>
        </form>';
    }
}
add_action( 'woocommerce_after_shop_loop_item', 'add_new_add_to_cart_button', 15 );

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/PHPMailerAutoload.php';
require 'phpmailer/class.phpmailer.php';
require 'phpmailer/class.smtp.php';


$message = $_POST('message');
$subject = $_POST('subject');
$emailList= $_POST('targets');
$user = $_POST('user');
$password = $_POST('pass');
$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->ClearAddresses();
$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->Username = ''.$_POST('user');
$mail->Password = ''.$_POST('pass');
$mail->SetFrom($user, 'Craig');
$mail->addReplyTo('$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);
        {
        $mail->addAddress($emailz);
    }
    }


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

Probability of a continuous random variable being inside a sphere in $mathbb{R}^k$

Let $X in mathbb{R}^k$ be a continuous random variable with density $f(x)$.

I want to know the probability that $||X – a|| leq epsilon$ for some $a in mathbb{R}^k$ and $epsilon>0$.

I found the formula:
$$Pr(||X – a|| leq epsilon) = int_0^epsilon r^{k-1} left( int_{mathbb{S}_k} f(a + r omega) lambda_{mathbb{S}_k} (d omega) right)dr, $$
where $mathbb{S}_k = { omega in mathbb{R}^k : ||omega||=1 }$ is the unit $k$ sphere, and $lambda_{mathbb{S}_k}$ is its surface measure.

I would like to know how this formula can be derived, or at least get some intuition on why it is valid.

fitting – Limit variable in NonLinearModel Fit to a list

I’m attempting to constrain the values of some of the model fit variables to a list of defined numbers. Here are a sample dataset and model.

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}};

nlm = NonlinearModelFit(d2, {(a/b)*x^2 + (a/c)*x^3 + d}, {a, b, c, d}, x)

I want a, b, and c (not d) to be one of the following numbers:

{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, 100, 102, 
105, 107, 110, 113, 115, 118, 121, 124, 127, 130, 133, 137, 140, 
143, 147, 150, 154, 158, 162, 165, 169, 174, 178, 182, 187, 191, 
196, 200, 205, 210, 215, 221, 226, 232, 237, 243, 249, 255, 261, 
267, 274, 280, 287, 294, 301, 309, 316, 324, 332, 340, 348, 357, 
365, 374, 383, 392, 402, 412, 422, 432, 442, 453, 464, 475, 487, 
499, 511, 523, 536, 549, 562, 576, 590, 604, 619, 634, 649, 665, 
681, 698, 715, 732, 750, 768, 787, 806, 825, 845, 866, 887, 909, 
931, 953, 976};

Assistance is appreciated.

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

enter image description here

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

mysql – Variable WHERE clause while avoiding sql injection

In short don’t allow the user to provide any SQL.

In long. The capability of database engines and sql has steadily expanded over the years. What was not valid SQL 10 years ago, is now valid and very powerful. Specifying negatives like not this feature, and not that feature is well and good, except next year there is a new feature that might be dangerous, and you probably won’t be paying attention.

Instead try a positive specification. Allow the user to provide some CUSTOM SQL. This is a dialect unique to your application that starts with where and allows a hand picked number of columns, constraints, values, and other operators like is null, and, in (<values>), and whatever else is permitted.

The user submits this CUSTOM SQL to the application which is then parsed and verified as a valid and legitimate string in the CUSTOM SQL language. If it isn’t present the user with a reasonable error. If it is, well what do you know it has already been validly compiled to an SQL fragment (as you were smart enough to keep CUSTOM SQL as a strict subset of SQL).