When you select another option than default on a mobile phone, the native mobile phone selection list appears. When you then select another option, the price changes however the selected weight does not appear in the selection box.
Open for example this page on the mobile phone.
<select class="variation-selector" id="<?php echo esc_attr( sanitize_title( $name ) ); ?>" name="attribute_<?php echo sanitize_title( $name ); ?>">
<option value="" disabled="disabled"><?php echo __( 'Choose an option', 'woocommerce' ) ?>…</option>
<?php
if ( is_array( $options ) ) {
if ( isset( $_REQUEST[ 'attribute_' . sanitize_title( $name ) ] ) ) {
$selected_value = $_REQUEST[ 'attribute_' . sanitize_title( $name ) ];
} elseif ( isset( $selected_attributes[ sanitize_title( $name ) ] ) ) {
$selected_value = $selected_attributes[ sanitize_title( $name ) ];
} else {
$selected_value = '';
}
// Get terms if this is a taxonomy - ordered
if ( taxonomy_exists( $name ) ) {
$orderby = wc_attribute_orderby( $name );
switch ( $orderby ) {
case 'name' :
$args = array( 'orderby' => 'name', 'hide_empty' => false, 'menu_order' => false );
break;
case 'id' :
$args = array( 'orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false );
break;
case 'menu_order' :
$args = array( 'menu_order' => 'ASC', 'hide_empty' => false );
break;
}
$terms = get_terms( $name, $args );
foreach ( $terms as $term ) {
if ( ! in_array( $term->slug, $options ) )
continue;
echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $term->slug ), false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';
}
} else {
foreach ( $options as $option ) {
echo '<option value="' . esc_attr( sanitize_title( $option ) ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
}
}
}
?>
</select>
Edit:
The above code outputs:
<select class="variation-selector selecter-element" id="pa_gewicht" name="attribute_pa_gewicht">
<option value="" disabled="disabled">Kies een optie…</option>
<option value="175-g" selected="selected">175 g</option>
<option value="350-g">350 g</option>
</select>
<div class="selecter closed">
<span class="selecter-selected">175 g</span>
<div class="selecter-options" style="display: none;">
<span class="selecter-item disabled first" data-value="">Kies een optie…</span>
<span class="selecter-item selected" data-value="175-g">175 g</span>
<span class="selecter-item last" data-value="350-g">350 g</span>
</div>
</div>
As you can see it duplicates it. Found out this is cause by a line in my javascript, namely:
$j(".orderby, .variations td.value select").selecter();
Which in turn uses the jquery.fs.selecter.min.js
Related
I have this code to display a menu in the header, but I want to show the child categories for the selected category page not the parents categories.
<?php
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
foreach ( $category_id as $navItem ) {
$class_names = $value = '';
$classes = empty( $navItem->classes ) ? array() : (array) $navItem->classes;
$classes[] = 'menu-item-' . $navItem->ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $navItem ) );
if ( in_array( 'current-menu-item', $classes ) )
$class_names .= ' active';
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $navItem->ID, $navItem );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
echo '<li ' . $id . ' ' . $class_names . '>'.$navItem->title.'</li>';
}
?>
thank you
Ok I have made some search and I was able to fix this one
this is the code
<?php
if(is_category() && the_category_ID(false) != NULL)
{
$categories = get_categories(array("child_of" => the_category_ID(false), "hide_empty" => 0));
foreach ($categories as $category)
{
$class_names = $value = '';
$classes = (array) $navitem ='';
$classes[] = 'menu-item-' . $category->cat_ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $category ) );
if ( in_array( 'current-menu-item', $classes ) )
$class_names .= ' active';
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $category->cat_ID, $category );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
echo '<li ' . $id . ' ' . $class_names . '>'.$category->cat_name.'</li>';
}
}
?>
hope it helps someone too
the_category_ID()
this one gets the ID of the current page category and we use false so it wont print the ID
and then loop inside for the sub-categories or child categories and gets their names + slug for URL
I am a yiibie, I have a question that I have a table named user_join_event which has id(PK) ngo_id(FK) event_id(FK) date_created date_modified as objects, and I want to get the 5 users Id's(which are repeated the most in this table) for every month. Like January top 5 users, Feb top 5 users and so on and then the top 5 users at the end of the year from this table, like once the year is completed it should give again the top 5 users from all over the month. Please help me with this, how to write an SQL query for this, thank you.
public function actionAllstats()
{
$this->layout='main';
$user=UserJoinEvent::model()->findAll(array(
'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
'param' => array(':year'=>2015, ':month'=>$yourMonth),
'select'=>'user_id',
'group'=>'user_id',
'order'=>'COUNT(*) DESC',
'limit' => 5
));
$this->render('allstats', array("user"=>$user));
}
and this is my view file
<div>
<?php
foreach($user as $show)
{
for($i = 1 ; $i <=12 ; $i++)
{
if($yourMonth == $i)
{
$model = User::model()->findByAttributes(array('id'=>$show->user_id,));
if (isset($model))
{
echo '<h3>' . $show->user_id . ' - ' . $model->username . '</h3>';
}
else {
echo '<h3>' . $show->user_id . ' - Username not found</h3>';
}
}
}
}
?>
</div>
For the Year you can sue this query for getting the users
$user=UserJoinEvent::model()->findAll(array(
'condition' => 'YEAR(date_create)=:year',
'params' => array(':year'=>2015)
'select'=>'user_id',
'group'=>'user_id',
'order'=>'COUNT(*) DESC',
'limit' => 5
));
and for the month you can do a loop from 1 to 12 using this query and set $yourMonth withe the value in loop
$user=UserJoinEvent::model()->findAll(array(
'condition' => 'YEAR(date_create)=:year and MONTH(date_create)=:month',
'params' => array(':year'=>2015, ':month'=>$yourMonth )
'select'=>'user_id',
'group'=>'user_id',
'order'=>'COUNT(*) DESC',
'limit' => 5
));
Controller action
public function actionAllstats()
{
$this->layout='main';
$myCurrYear = date("Y")
$userYear=UserJoinEvent::model()->findAll(array(
'condition' => 'YEAR(date_create)=:year',
'params' => array(':year'=>$myCurrYear)
'select'=>'user_id',
'group'=>'user_id',
'order'=>'COUNT(*) DESC',
'limit' => 5
));
$this->render('allstats', array("userYear"=>$userYear));
}
View
This view in not based on good pratice, because use access to model inside a view. is a trial for lead you to understand some of the problem related with question.
<?php // this for the twelve month
for($month = 1 ; $month <=12 ; $month++) {
<div>
$user=UserJoinEvent::model()->findAll(array(
'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
'params' => array(':year'=>2015, ':month'=>$month),
'select'=>'user_id',
'group'=>'user_id',
'order'=>'COUNT(*) DESC',
'limit' => 5
));
foreach($user as $show) {
$model = User::model()->findByAttributes(array('id'=>$show->user_id,));
if (isset($model)) {
echo '<h3>' . $show->user_id . ' - ' . $model->username . '</h3>';
}
else {
echo '<h3>' . $show->user_id . ' - Username not found</h3>';
}
}
</div>
}
?>
<div>
<?php // the for the year
foreach($userYear as $show) {
$model = User::model()->findByAttributes(array('id'=>$show->user_id,));
if (isset($model)) {
echo '<h3>' . $show->user_id . ' - ' . $model->username . '</h3>';
}
else {
echo '<h3>' . $show->user_id . ' - Username not found</h3>';
}
}
?>
</div>
I'm running a query against a database and have to check for multiple conditions to be true. The code I have pulls the data I want, but if I had to check many more columns, it could get out of control very quickly. I don't want a query that where I have to write out a dozen or so "AND" conditions. I'm learning some MySQL as I go and any help would be appreciated.
<?php
$servername = "localhost";
$username = "xxxx";
$password = "xxxx";
$dbname = "oldga740_SeniorProject";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Set up and run my Query
$sql = "SELECT Project, Client, DateReceived, LastName, FinalReviewDate FROM Projects
WHERE FinalReviewDate IS NOT NULL
AND DateDelivered IS NULL
AND DateAccepted IS NULL
ORDER BY DateAccepted DESC";
$result = $conn->query($sql);
//Display results
if ($result->num_rows > 0) {
echo "<table><tr><th>Client</th><th>Project</th><th>Point of Contact</th><th>Date Project Received</th><th>Final Review Date</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["Client"]. "</td><td>" . $row ["Project"]. "</td><td> " . $row["LastName"]. "</td><td> " . $row ["DateReceived"]. "</td><td> " . $row["FinalReviewDate"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
You can use an array for your and conditions. But in general you have to be careful if you are going to have prepared statements and bind values. Also, you can create your WHERE clause dynamically in a similar way like the following:
EDIT:
$where = array(
array(
'column'=>'FinalReviewDate',
'operator'=>'AND',
'condition'=>'IS NOT NULL',
'value'=>'',
),
array(
'column'=>'DateDelivered',
'operator'=>'AND',
'condition'=>'IS NULL',
'value'=>'',
),
array(
'column'=>'DateAccepted',
'operator'=>'AND',
'condition'=>'IS NULL',
'value'=>'',
),
array(
'column'=>'other_column',
'operator'=>'OR',
'condition'=>'>=',
'value'=>5,
),
);
$temp = array();
foreach($where as $key => $value) {
if ($value['value'] == '') {
$temp[] = $value['operator'].' '.$value['column'].' '.$value['condition'];
} else {
$temp[] = $value['operator'].' '.$value['column'].' '.$value['condition'].' '.$value['value'];
}
}
$where_sql = '1 = 1 '.implode(' ', $temp);
echo $where_sql;
Result:
1 = 1 AND FinalReviewDate IS NOT NULL AND DateDelivered IS NULL AND DateAccepted IS NULL OR other_column >= 5
OLD ANSWER
$ands = array(
array(
'column'=>'FinalReviewDate',
'condition'=>'IS NOT NULL'
),
array(
'column'=>'DateDelivered',
'condition'=>'IS NULL'
),
array(
'column'=>'DateAccepted',
'condition'=>'IS NULL'
),
);
$temp = array();
foreach($ands as $key => $value) {
$temp[] = $value['column'].' '.$value['condition'];
}
$and_sql = implode(' AND ', $temp);
echo $and_sql;
Result:
FinalReviewDate IS NOT NULL AND DateDelivered IS NULL AND DateAccepted IS NULL
I've got a webshop running with woocommerce. The webshop has products with variations. When I add the same product with the same variation, I want it to generate a new order_item_id, in stead of combining the two under the same order_item_id.
I can't seem to find the bit of code that is responsible for generating the order_item_id.
Could anyone tell me where this bit of code is located?
My goal is to make each product unique in stead of stacking items that are the same.
-EDIT
Ok, so I've narrowed it down to class-wc-cart.php
On line 782 the product ID is generated with the following code:
public function generate_cart_id( $product_id, $variation_id = '', $variation = '', $cart_item_data = array() ) {
$id_parts = array( $product_id );
if ( $variation_id ) $id_parts[] = $variation_id;
if ( is_array( $variation ) ) {
$variation_key = '';
foreach ( $variation as $key => $value ) {
$variation_key .= trim( $key ) . trim( $value );
}
$id_parts[] = $variation_key;
}
if ( is_array( $cart_item_data ) && ! empty( $cart_item_data ) ) {
$cart_item_data_key = '';
foreach ( $cart_item_data as $key => $value ) {
if ( is_array( $value ) ) $value = http_build_query( $value );
$cart_item_data_key .= trim($key) . trim($value);
}
$id_parts[] = $cart_item_data_key;
}
return md5( implode( '_', $id_parts ) );
}
Now all that is left is to edit in a unique ID via a timestamp or something.
Will keep you guys posted.
Solved it.
Open class-wc-cart.php, and add a timestamp, or anything else that is unique to $id_parts.
Just like in the following code:
public function generate_cart_id( $product_id, $variation_id = '', $variation = '', $cart_item_data = array() ) {
$id_parts = array( $product_id );
if ( $variation_id ) $id_parts[] = $variation_id.time();
if ( is_array( $variation ) ) {
$variation_key = '';
foreach ( $variation as $key => $value ) {
$variation_key .= trim( $key ) . trim( $value );
}
$id_parts[] = $variation_key.time();
}
if ( is_array( $cart_item_data ) && ! empty( $cart_item_data ) ) {
$cart_item_data_key = '';
foreach ( $cart_item_data as $key => $value ) {
if ( is_array( $value ) ) $value = http_build_query( $value );
$cart_item_data_key .= trim($key) . trim($value);
}
$id_parts[] = $cart_item_data_key.time();
}
return md5( implode( '_', $id_parts ) );
}
I'm starting in jquery, and I am trying to load the data from a php file to the jQuery.Gantt (http://taitems.github.io/jQuery.Gantt/). But the chart does load.
The script:
$(".gantt").gantt({
source: 'gantt_data_json.php',
navigate: "scroll",
scale: "weeks",
maxScale: "months",
minScale: "days",
itemsPerPage: 10,
....
});
The gantt_data_json.php:
require_once('libs/common.php');
$query ="SELECT * from gantt_table";
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$gantt[] = array(
'name' =>$row['name'],
'desc' => $row['desc'],
'values' => array(
'to' => '/Date('.strtotime($row['to']).')/',
'from' => '/Date('.strtotime($row['from']).')/',
'desc' =>$row['desc2'],
'label' => $row['label'],
'customClass' => 'ganttRed'
)
);
}
echo json_encode($gantt);
Please could you help me to solve this issue?
Try this:
$query = "SELECT * from gantt_table";
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
$gantt = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data[] = array(
'name' => $row['name'],
'desc' => $row['desc'],
'values' => array(
array(
'from' => '/Date(' . $row['from'] . ')/',
'to' => '/Date(' . $row['to'] . ')/',
'desc' => $row['desc2'],
'label' => $row['label'],
'customClass' => 'ganttRed',
),
)
);
$gantt[] = $data;
}
echo json_encode($gantt);
its workfine
$json = Array();
while ($rs = mysqli_fetch_array($rsPedidos))
{
$data[] = array(
'name' => $rs['projeto'],
'desc' => $rs["site"],
$valor[] = array(
'from' => '/Date(' . strtotime($rs["data_inicio_ti"]) . '000)/',
'to' => '/Date(' . strtotime($rs["data_fim_ti"]) . '000)/',
'desc' => $rs["funcionario"].' / PO:'.$rs["numero_po"].' / R$:'.$rs["valor_po"],//12658580,//1320192000000 1497582000
'label' => $rs["servico"],
'customClass' => 'ganttRed',
),
'values' =>$valor,
);
$json = $data;
}
print json_encode($json);