We have this code to display the custom field in WordPress
if( isset($digi) && !empty($digi) )
Now we want to add a new condition (check in terms of being categorized)
That's how we did it
if( isset(product_categories=55,56,57,58) || isset($digi) && !empty($digi) )
Is it correct?
I am not sure in what file or loop you perform this code, but your solution might be something similair to this:
$your_category = "THE CATEGORY YOU WANT TO CHECK FOR";
$product_categories = array(55,56,57,58);
if( in_array($your_categroy, $product_categories) || ( isset($digi) && !empty($digi) ) )
Related
So, prefix that my coding level is practically equal to zero...
I'm using Wordpress with Wp All Import plugin, and i have this code to prevent wpallimport to create new categories/taxonomies etc.
function dont_create_terms( $term_into, $tx_name ) {
// Check if term exists, checking both top-level and child
// taxonomy terms.
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
// If the term already exists assign it.
return $term_into;
}
add_filter( 'pmxi_single_category', 'dont_create_terms', 10, 2 );
Now, as specified in the title, i have to run this code only for certain taxonomies...
I have tried multiple solutions, for last i tried to add this line
if ($tx_name == 'taxonomyname') {
like here
function dont_create_terms( $term_into, $tx_name ) {
// Check if term exists, checking both top-level and child
// taxonomy terms.
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
if ($tx_name == 'taxonomyname') {
// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
// If the term already exists assign it.
return $term_into;
}
add_filter( 'pmxi_single_category', 'dont_create_terms', 10, 2 );
but everytime nothing appens.
Any help is really appreciated, thanks to everyone in advance
Edit:
Solution found
function dont_create_terms( $term_into ) {
// Check if term exists, checking both top-level and child
// taxonomy terms.
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
if ( $tx_name == 'taxonomy_name' ){
// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
// If the term already exists assign it.
return $term_into;
}
add_filter( 'pmxi_single_category', 'dont_create_terms', 10, 2 );
And than call the function:
[dont_create_terms({yourxmldata[1]})]
Edit 2
It only works with single taxonomies, if the taxonomies contain multiple values it will not work
So again, if you have any suggestions you are welcome
The right way to do this would be writing your our custom function as shown here: https://www.wpallimport.com/documentation/code-snippets/#reference-taxonomy-terms-by-custom-id
However, although it is not elegant at all, I have found a different solution that could work for some, which involves wp-all-import's [foreach()] function.
It is not flexible as it requires that you add the max amount of values possible in your file (e.g 6 values tops in this example):
[foreach( {ParentNode/CategoryNode} )] {#id} > {Value1} |
{#id} > {Value[2]} | {#id} > {Value[3]} | {#id} > {Value[4]} |
{#id} > {Value[5]} | {#id} > {Value[6]} | [endforeach]
Where {ParentNode/CategoryNode} + #id + Value represent this portion of the xml file:
<ParentNode>
<CategoryNode id="this-cat-id">
<Value>Your value here</Value>
</CategoryNode>
</ParentNode>
Important: This will generate this error log while importing, every time it tries to import a value that does not exist, but the import will still work:
WARNING: It is necessary to assign a name to this term.
Important:
(1) In the import settings, you will need to go to 'Taxonomies, Categories, Tags', and select 'An element in my file contains the entire hierarchy...'.
(2) Then, check 'Separate hierarchy groups via symbol'.
(3) Do not check 'Only assign Your-cat-name-goes-here to the bottom level term in the hierarchy'
Here is how I set it up....
Screenshot WPAllImport
Hope this helps newcomers!
We are using the Easy Booking plugin for a client’s project and they want the ability to make the dates recurring. I.E they use the calendar to book Mon, Tues and Wed and want to have it recurring for the next 3 weeks.
We added some JS functionality, with a few form fields, that modifys the data-booking_price so that it is the price * recurring modifier. The order flow works fine while the quantity is one, but if we increase the quantity, the whole thing breaks apart. After we add the item to the cart and then go to View Cart, the price is set to the original booking price, sans the modifier.
You can view it in action here: http://bethpark.dev.ksand.com/product/meter-bags
My question is how does how does the plugin pass the total of the product along to the cart? From what I can see, it’s not updating Woo Sessions with the total that is getting generated. Is that not accurate? I realize we are modifying how the plugin inherenly works, but any sort of pointing in the right direction would be much appreciated!
-Anthony
I've updated WC()->cart->total on both the cart page and the checkout page, but it keeps getting overwritten. I've also manually set the total in WC()->sessions but that also get's overwritten (I've since commented these out since this felt extremely hacky.)
//function to detect if PHP session is started
function is_session_started()
{
if ( php_sapi_name() !== 'cli' ) {
if ( version_compare(phpversion(), '5.4.0', '>=') ) {
return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
} else {
return session_id() === '' ? FALSE : TRUE;
}
}
return FALSE;
}
add_action( 'woocommerce_before_add_to_cart_button' , 'bpa_custom_add_checkout_fields', 50, 0 );
function save_recursion(){
//if the user is getting the bags with recursive dates set, we will attempt to save them so that they can be used at a later time.
if( isset($_POST['recursive_weeks']) ){
$id = 0;
if( is_user_logged_in() ){
$id = get_current_user_id();
}
// if user is not logged in or if WP couldn't get user ID
if($id > 0){
update_user_meta($id, 'bpa_meter_bag_recursion', $_POST['recursive_weeks']);
} else {
if ( is_session_started() === FALSE ) session_start();
$_SESSION['bpa_meter_bag_recursion'] = $_POST['recursive_weeks'];
}
}
}
add_action('woocommerce_add_to_cart', 'save_recursion');
function custom_add_to_cart( $item_data, $cart_item) {
//this adds the custom recursion dates to the items data
//if this is the meter bag product
if($cart_item['product_id'] == '2476'){
//check if user is logged in, get recursion from user meta. if not try to get sessions
if( is_user_logged_in() ){
$id = get_current_user_id();
$recursion = get_user_meta($id, 'bpa_meter_bag_recursion');
$_POST['recursive_weeks'];
} else {
session_start();
$recursion = $_SESSION['bpa_meter_bag_recursion'] ;
}
// change the message to reflect that this is going to be multiple dates
$item_data[0]['name'] = "First Day of First Week";
$item_data[1]['name'] = "Last Day of First Week";
//get that first week dates in the correct format
$start_date = new DateTime($item_data[0]['value']);
$end_date = new DateTime($item_data[1]['value']);
$first_start_date = $start_date->format('Y-m-d');
$first_end_date =$end_date->format('Y-m-d');
//iterate over the recursive weeks and add these as products to the cart
$week = 1;
$quantity = $cart_item['quantity'];
for($i = 1; $i <= ($recursion[0] * 2) - 2; $i++ ){
if( ($i % 2) != 0){
$item_data[$i + 1]['name'] = "First Day of the Next Week ";
$startDate = strtotime( $first_start_date . " +" . $week ." week" );
$item_data[$i + 1]['value'] = date('F jS Y', $startDate);
} else {
$item_data[$i + 1]['name'] = "Last Day of the Next Week ";
$endDate = strtotime( $first_end_date . " +" . $week ." week");
$item_data[$i + 1]['value'] = date('F jS Y', $endDate);
$week++;
}
}
if ( is_session_started() === FALSE ) session_start();
$_SESSION['recursive_dates'] = serialize($item_data);
if( isset($_SESSION['recursive_dates']) ){
//var_dump($_SESSION['recursive_dates']);
}
return $item_data;
}
}
add_filter('woocommerce_get_item_data', 'custom_add_to_cart', 10, 2);
What I am expecting to have happen is that on the product screen, the updated product total would get added to the cart total, and viewable from the cart and checkout. This works until the quantity is increased. Not sure why this is an issue since I would presume that the total would be prod_total * quantity, but that doesn't appear to be how this works. I'm not sure if this is a woo thing or an Easy Bookings thing (I'm tending to lean towards a woo thing, but my hours of research hasn't found anything, or I'm googling the wrong stuff. )
Any help in pointing me in the right direction is mucho appreciated.
Is it possible to assign
get_theme_mod('dds') !== 'false';
to a variable and include it in an if statement instead of typing the whole thing?
This is the if statement I am dealing with:
$DDS = get_theme_mod('dds') !== 'false';
if( is_category() && $DDS ) :
//output some css style
endif;
I get an error: Parse error: syntax error, unexpected ':'
You get error because of you are not complete if statement bracket see below code to remove error.
$DDS = get_theme_mod('dds') !== 'false';
if( is_category() && $DDS ) :
//output some css style
endif;
Another solution: no need to make variable you can direct add code in if condition you get same solution as above code
if( is_category() && ( get_theme_mod('dds') !== 'false' ) ) :
//output some css style
endif;
Why do you need != false at all, seems redundant?
I've wrote the following Doctrine query:
$query3 = $this->entityManager
->createQueryBuilder()
->select('t.textDomain , t.translationKey , t.languageIso , t.translationDate')
->from(
'AMDatabase\Entity\TheVerse\TranslationsMasters',
't'
)
->groupBy('t.languageIso')
->orderBy(
't.translationDate',
'DESC'
);
// the values of $key2 array are:
// en-US
// es-MX
// es-PR
foreach( $translation AS $key2=>$value2 ) {
if ( $key2 == 'en-US' ) {
$query3
->orWhere(
$query3->expr()
->like(
't.languageIso',
':languageIso'
)
)
->setParameter(
'languageIso',
$key2
);
}
}
$result3 = $query3->getQuery()
->getArrayResult();
How do I have the query search for all 3 language ISO's at the same time?
With "if ( $key2 == 'en-US' ) {" the query executes and gives me the expected result.
But if I remove "if ( $key2 == 'en-US' ) {" there are no search results.
I thought by using "orWhere" it would keep adding conditions to the query (where en-US will still produce a match).
In haven't ever been able to get orWhere to function the way I think it should. It might be that you need a Where in your opening definition before you can add an orWhere later. You might have to use the nested orX statement like this instead:
$query3->andWhere($query3->expr()->orX(
$query3->expr()->like('t.languageIso', $query3->expr()->literal('en-US')),
$query3->expr()->like('t.languageIso', $query3->expr()->literal('es-MX')),
$query3->expr()->like('t.languageIso', $query3->expr()->literal('es-PR'))
));
You can't develop the statement through a loop. But, since you've only got three criteria, it's easy enough to write out.
Pretty much as per the question, how would I go about creating a view that only showed content older than the current node's created date?
I've created the argument using 'Content: created date' but struggling to pass this over to the filter criteria.
To be honest, I'm not even sure this is the correct way to do it!
Managed to get this working with a Views PHP field:
<?php
global $base_path;
if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
$node = node_load(arg(1));
$a1 = format_date($node->created, 'custom', 'm/d/Y');
$a2 = date("m/d/Y",strtotime("-2 months",strtotime($a1)));
$a3 = format_date($row->created, 'custom', 'm/d/Y');
$b1 = new DateTime($a1);
$b2 = new DateTime($a2);
$b3 = new DateTime($a3);
if ($b3 >= $b2 && $b3 <= $b1) {
print '<h2>' . $row->title . '</h2>' . $data->field_body[0]['rendered']['#markup'];
//dsm($data);
}
}
?>