Woocommerce select country dropdown: how to remove default option and do not update_totals_on_change? - select

I have standard woocommerce select dropdown on checkout page with shipping_country and billing_country.
Can I remove first option with value=default using any hook? Or only by jQuery?
After the country have been changed woocommerce triggers an action updated_cart_totals. But I do not need it. To not trigger updated_cart_totals it is enough to remove update_totals_on_change class. Can I remove it using any hook? Or the same only by jQuery?
<p class="form-row form-row-wide address-field update_totals_on_change" id="shipping_country_field" data-priority="40">
<select name="shipping_country" id="shipping_country" class="country_to_state" autocomplete="country" tabindex="-1" aria-hidden="true">
<option value="default">Land/Region auswählen …</option>
<option value="BE">Belgien</option>
<option value="DE">Deutschland</option>
<option value="LU">Luxemburg</option>
<option value="NL" selected="selected">Niederlande</option>
</select>
</p>
UPDATE
1 question.
This is how fields are generated in form-shipping.php or form-billing.php:
foreach ( $fields as $key => $field ) {
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
}
Look in woocommerce_form_field code:
2726 function woocommerce_form_field( $key, $args, $value = null ) {
.....
2803 switch ( $args['type'] ) {
case 'country':
$countries = 'shipping_country' === $key ? WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries();
if ( 1 === count( $countries ) ) {
$field .= '<strong>' . current( array_values( $countries ) ) . '</strong>';
$field .= '<input type="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . current( array_keys( $countries ) ) . '" ' . implode( ' ', $custom_attributes ) . ' class="country_to_state" readonly="readonly" />';
} else {
$data_label = ! empty( $args['label'] ) ? 'data-label="' . esc_attr( $args['label'] ) . '"' : '';
2816 $field = '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="country_to_state country_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_attr__( 'Select a country / region…', 'woocommerce' ) ) . '" ' . $data_label . '><option value="">' . esc_html__( 'Select a country / region…', 'woocommerce' ) . '</option>';
foreach ( $countries as $ckey => $cvalue ) {
$field .= '<option value="' . esc_attr( $ckey ) . '" ' . selected( $value, $ckey, false ) . '>' . esc_html( $cvalue ) . '</option>';
}
$field .= '</select>';
$field .= '<noscript><button type="submit" name="woocommerce_checkout_update_totals" value="' . esc_attr__( 'Update country / region', 'woocommerce' ) . '">' . esc_html__( 'Update country / region', 'woocommerce' ) . '</button></noscript>';
}
break;
In the end of 2816 line we can see . '><option value="">' . esc_html__( 'Select a country / region…', 'woocommerce' ) . '</option>';
So 1st question solved - it is impossible to remove this option using any hook ((( only js/jQuery.
UPDATE
2 question.
Removing update_totals_on_change class can help not to updated_cart_totals only if we use select2 (selectwoo). If we deenqueue select2 then updated_cart_totals triggers every time select changed even without above class.
So the question is still how to disable that trigger on select country change?

Related

Laravel 8 Old Value in select

Im trying to get the selected category while validating inputs,
Please need help
in blade:
{{__("-- Please Select --")}}
category_id === $category->id)
$selected = 'selected';
printf("%s", $category->id, $selected, $prefix . ' ' . $category->name);
$traverse($category->children, $prefix . '-');
}
};
$traverse($tour_category);
?>
Thanks

pg_fetch_assoc returning 1 after values

I am beginner in PHP, i am working with session and pg functions. So i want to return user's first name and last name from database(basically user's details) and display it to different page using session. and it is returning using pg_fetch_assoc() but the problem is like it is showing 1 after every value like (firstname 1), (lastname 1). How can i fix it. is there any other way to return values from database and display it and also use these values as conditions.
Thanks
Below is my code:
$login = trim($_POST['login']);
$pass = trim($_POST['pass']);
$result = pg_execute($conn, "login_query", array($login, hash(HASH_ALGO, $pass)));
$records = pg_num_rows($result);
if($records == 1){
$_SESSION['user_id'] = $login;
$row = pg_fetch_assoc($result);
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['last_name'] = $row['last_name'];
$_SESSION['last_access'] = $row['last_access'];
$_SESSION['user_type'] = $row['user_type'];
//$_SESSION['details'] = $row;
pg_execute($conn, "update_query", array($login));
/* $_SESSION['output'] = $output();*/
$_SESSION['output'] = "Welcome back " . pg_fetch_result($result,0,"first_name") . pg_fetch_result($result,0,"last_name").'</br>';
$_SESSION['output'] .= "Our records show that your </br>" . "email address is " . pg_fetch_result($result,0,"email_address") . "</br>";
$_SESSION['output'] .= "and you last accessed our system: " . pg_fetch_result($result,0,"last_access") . "</br>";
header('location: ./user-dashboard.php');
}
here is var_dump($row); value:
array(9) { ["user_id"]=> string(20) "jdoe " ["password"]=> string(32) "179ad45c6ce2cb97cf1029e212046e81" ["user_type"]=> string(2) "c " ["email_address"]=> string(256) "jdoe#gmail.com " ["first_name"]=> string(128) "John " ["last_name"]=> string(128) "Doe " ["birth_date"]=> string(10) "1998-02-05" ["enrol_date"]=> string(10) "2017-01-01" ["last_access"]=> string(10) "2017-10-18" }
database
pg_fetch_assoc returns values OK. you can see it in result of var_dump($row); - see the ["last_name"]=> string(128) "Doe " - it has extra space - yes, but not 1. So another bit of code adds 1 after $row["last_name"] value.
<h1 class="floating-box" ><?php echo print_r($_SESSION['first_name'],True); ?></h1>
<h1 class="floating-box" ><?php echo print_r($_SESSION['last_name']); ?></h1>
<h1 class="floating-box" ><?php echo print_r($_SESSION['last_access']); ?></h1>
Sorry, i forgot to add true in print_r() function. Thanks for your help. #Vao Tsun

Sort order list view by 'logged in user' in SuiteCRM

Removing default sort order in list view and sorting by 'Logged in user' in SuiteCRM.
Add the following code in custom/modules/Prospects(your module)/views/view.list.php
function listViewProcess() {
global $current_user;
$user_name = $current_user->user_name;
$id = $current_user->id;
$this->processSearchForm();
$this->params['custom_order_by'] = ' ORDER BY FIELD(assigned_user_id, "'.$id.'") DESC';
$this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
$savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
echo $this->lv->display();
}
custom_order_by will be considered as second order by field
so declare
$ret_array['order_by']=''; in include/ListView/ListViewData.php
before
$main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
Without customizing the code in include/listView/ListViewDate.php, just add the following code in custom/modules/(your module)/views/view.list.php
function listViewProcess() {
global $current_user;
$user_name = $current_user->user_name;
$id = $current_user->id;
$this->processSearchForm();
$this->params['overrideOrder']='1';
$this->params['orderBy']='1';
$this->params['custom_order_by'] = ' ORDER BY FIELD(accounts.assigned_user_id, "'.$id.'") DESC';
$this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
$savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : (' - ' . $_REQUEST['saved_search_select_name']);
echo $this->lv->display();
}

zend search lucence return hit id of search insted id of field

i have poblem zend search lucence :
zend search lucence return hit id of search insted id of field.for example:
i have this codde in Yii controller for create index of news data:
public function createNewsIndex()
{
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles.'.news'), true);
$news= News::model()->findAll();
foreach ($news as $newsItem) {
$news_doc=new Zend_Search_Lucene_Document();
$news_doc->addField(Zend_Search_Lucene_Field::Text('id',CHtml::encode($newsItem->id),'utf-8'));
$news_doc->addField(Zend_Search_Lucene_Field::Text('title',CHtml::encode($newsItem->title),'utf-8'));
$news_doc->addField(Zend_Search_Lucene_Field::Text('keywords',CHtml::encode($newsItem->keywords),'utf-8'));
$index->addDocument($news_doc);
}
$index->commit();
$index->optimize();
}
i have this code for search news :
public function searchNews($term) {
setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
try
{
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles . '.news'));
}
catch(Zend_Search_Lucene_Exception $e)
{
$this->createNewsIndex();
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles . '.news'));
}
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
$results = $index->find($term . '*');
$this->render('search', array(
'results' => $results,
)
}
and this code in view:
<?php foreach ($results as $result)
{
print "ID: " . $result->id . "\n";
print "Score: " . $result->title . "\n<br>";
print CHtml::link(CHtml::encode($result->title), array($controller.'/view', 'id'=>$result->id));
}
?>
i want $result->id be id of this news title but I think this is a hit ID of I think this is a test Aht ID. hit in find function according this link:(see find function)
http://phpcrossref.com/zendframework/library/Zend/Search/Lucene.php.html
.
Sorry for weak English.
i fix problem by rename id field name:
$news_doc->addField(Zend_Search_Lucene_Field::Text('news_id',CHtml::encode($newsItem->id),'utf-8'));
and in view:
<?php foreach ($results as $result)
{
print "ID: " . $result->news_id . "\n";
print "Score: " . $result->title . "\n<br>";
print CHtml::link(CHtml::encode($result->title), array($controller.'/view', 'id'=>$result->news_id));
}
?>

How do I add a class name to <li> from Zend Navigation XML

Can someone please help me out, I'm totally stuck! I don't know how to add a class name to <li> tag in Zend navigation XML
This is my XML
<configdata>
<nav>
<home>
<label>Home </label>
<uri>/</uri>
</home>
<request>
<label>Quotes </label>
<uri>/quote</uri>
</request>
<work>
<label>How It Works</label>
<uri>/how-it-works</uri>
</work>
<information>
<label>Informations </label>
<uri>/informations</uri>
</information>
<directory>
<class> last </class>
<label>Directory </label>
<uri>/directory</uri>
</directory>
</nav>
</configdata>
When I add <class>last</class> this is what i get:
<li>
<a class="last" href="/directory">Directory </a>
</li>
Currently I'm getting <a class="last"> but I need <li class="last">
Thanks so much in advance!
Cheers
I think that the best way to put css classes into li elements would be to write your own navigation menu helper, called for example My_View_Helper_NavigationMenu that extends original Zend_View_Helper_Navigation_Menu class. For this reason I prepared an example of such a helper that overloads _renderMenu() method. The code of the method seems long, but this is because original code is long. There are only few new/modified lines in overloaded _renderMenu():
File: APPLICATION_PATH/views/helpers/NavigationMenu.php
class My_View_Helper_NavigationMenu extends Zend_View_Helper_Navigation_Menu {
/**
* Renders a normal menu (called from {#link renderMenu()})
*
* #param Zend_Navigation_Container $container container to render
* #param string $ulClass CSS class for first UL
* #param string $indent initial indentation
* #param int|null $minDepth minimum depth
* #param int|null $maxDepth maximum depth
* #param bool $onlyActive render only active branch?
* #return string
*/
protected function _renderMenu(Zend_Navigation_Container $container,
$ulClass,
$indent,
$minDepth,
$maxDepth,
$onlyActive)
{
$html = '';
// find deepest active
if ($found = $this->findActive($container, $minDepth, $maxDepth)) {
$foundPage = $found['page'];
$foundDepth = $found['depth'];
} else {
$foundPage = null;
}
// create iterator
$iterator = new RecursiveIteratorIterator($container,
RecursiveIteratorIterator::SELF_FIRST);
if (is_int($maxDepth)) {
$iterator->setMaxDepth($maxDepth);
}
// iterate container
$prevDepth = -1;
foreach ($iterator as $page) {
$depth = $iterator->getDepth();
$isActive = $page->isActive(true);
if ($depth < $minDepth || !$this->accept($page)) {
// page is below minDepth or not accepted by acl/visibilty
continue;
} else if ($onlyActive && !$isActive) {
// page is not active itself, but might be in the active branch
$accept = false;
if ($foundPage) {
if ($foundPage->hasPage($page)) {
// accept if page is a direct child of the active page
$accept = true;
} else if ($foundPage->getParent()->hasPage($page)) {
// page is a sibling of the active page...
if (!$foundPage->hasPages() ||
is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
// accept if active page has no children, or the
// children are too deep to be rendered
$accept = true;
}
}
}
if (!$accept) {
continue;
}
}
// make sure indentation is correct
$depth -= $minDepth;
$myIndent = $indent . str_repeat(' ', $depth);
if ($depth > $prevDepth) {
// start new ul tag
if ($ulClass && $depth == 0) {
$ulClass = ' class="' . $ulClass . '"';
} else {
$ulClass = '';
}
$html .= $myIndent . '<ul' . $ulClass . '>' . self::EOL;
} else if ($prevDepth > $depth) {
// close li/ul tags until we're at current depth
for ($i = $prevDepth; $i > $depth; $i--) {
$ind = $indent . str_repeat(' ', $i);
$html .= $ind . ' </li>' . self::EOL;
$html .= $ind . '</ul>' . self::EOL;
}
// close previous li tag
$html .= $myIndent . ' </li>' . self::EOL;
} else {
// close previous li tag
$html .= $myIndent . ' </li>' . self::EOL;
}
// ***************** THESE ARE NEW LINES *************** //
$liMyClass = $page->get('liclass') ? $page->liclass : '' ;
if ($isActive) {
$liClass = " class=\"active $liMyClass\" ";
} else {
$liClass = $liMyClass ? " class=\"$liMyClass\" ":'';
}
// ***************** END OF NEW STUFF *************** //
// render li tag and page (ORGINAL LINE REMOVED)
//$liClass = $isActive ? ' class="active "' : '';
$html .= $myIndent . ' <li' . $liClass . '>' . self::EOL
. $myIndent . ' ' . $this->htmlify($page) . self::EOL;
// store as previous depth for next iteration
$prevDepth = $depth;
}
if ($html) {
// done iterating container; close open ul/li tags
for ($i = $prevDepth+1; $i > 0; $i--) {
$myIndent = $indent . str_repeat(' ', $i-1);
$html .= $myIndent . ' </li>' . self::EOL
. $myIndent . '</ul>' . self::EOL;
}
$html = rtrim($html, self::EOL);
}
return $html;
}
}
In your layout.phtml you need to indicate to the navigation view helper to use this new class. You can do this as follows:
<?php $this->navigation()->setDefaultProxy('navigationMenu'); ?>;
Finally in your navigation.xml you could define a class for a li element using liclass tag (you can use whatever name you want for this tag):
<directory>
<class> last </class>
<label>Directory </label>
<uri>/directory</uri>
<liclass>someclass</liclass>
</directory>
Hopefully this will be helpful to you. Ideally, I should have named the new class My_View_Helper_Navigation_Menu (located in APPLICATION_PATH/views/helpers/Navigation/Menu.php). However, I could not make Zend plugin loaders to load it and I went with My_View_Helper_NavigationMenu.