Jump to content

jarvis

Members
  • Content Count

    464
  • Joined

  • Last visited

Community Reputation

1 Neutral

About jarvis

  • Rank
    Advanced Member

Profile Information

  • Gender
    Not Telling
  1. Thanks @requinix It's usually done this way due to the number of redirects and from an admin point of view (someone else maintains it). I thought adding both functions would cater for trailing slash and non-trailing slash I'll review it again
  2. Hi All, Am having a "can't see the wood for the trees" moment I have a php redirect file which contains my URLs, like so: return [ '/shop/' => '/products/', ]; I then have a functions file which contains: function 301_redirects(){ $redirects = include __DIR__ . '/redirects.php'; if (isset($redirects[$_SERVER['REQUEST_URI']])) { header("HTTP/1.1 301 Moved Permanently"); header('location: ' . $redirects[$_SERVER['REQUEST_URI']]); exit; } if (isset($redirects[rtrim($_SERVER['REQUEST_URI'], '/')])) { header("HTTP/1.1 301 Moved Permanently"); header('location: ' . $redirects[rtrim($_SERVER['REQUEST_URI'], '/')]); exit; } } If the URL is https://www.mydomain.com/shop then the redirect won't work If the URL is https://www.mydomain.com/shop/ then the redirect works What am I missing? Thanks
  3. Thank you Barand, I shall digest this today!
  4. I "think" I may have sussed this: add_filter( 'gform_pre_render_2', 'applicant_2_previous_address_history' ); add_filter( 'gform_pre_validation_2', 'applicant_2_previous_address_history' ); function applicant_2_previous_address_history( $form ) { #get the value from the form date input d/m/Y so need to change $get_moved_in_date = rgpost( 'input_1' ); if ( $get_moved_in_date ) { #convert the date format $moved_in_date = date_format(date_create_from_format('d/m/Y', $get_moved_in_date), 'd-m-Y'); #echo "New date format is: ".$moved_in_date. "<br/>"; } #get todays date $today = date("d-m-Y"); #echo "<h3>Today: ".$today."</h3>"; #calculate the difference in days $dateDiff = dateDiffInDays($today, $moved_in_date); #printf("<p>Difference between two dates: " . $dateDiff . " Days</p>"); if ( $dateDiff < 1095 ) { #$flag = 'true'; # get the input from the list $list_values = rgpost( 'input_2' ); $i = 0; #use this to get even rows only due to the way data is stored :( $sum = 0; #use this to increment the no. of rows in the list $previous = null; #use this to calc date difference between rows $days_sum = $dateDiff; #set the total number of days. Don't start at 0, start from current date - time at current residence if ( $list_values ) { foreach ( $list_values as $key => $value ){ #get even rows only if($i%2 == 0){ $sum = $sum + 1; #increment our rows if ( $value ) { #convert the date format $additional_date = date_format(date_create_from_format('d/m/Y', $value), 'd-m-Y'); echo "<h3>Date: ".$additional_date."</h3>"; } if ( $previous !== null ){ # if it's null, we're in the first loop #convert the date format $previous_date = date_format(date_create_from_format('d/m/Y', $previous), 'd-m-Y'); $dateDiff2 = dateDiffInDays($additional_date, $previous_date); printf("<p>Next Iteration Difference between " . $additional_date . " and " . $previous_date . " is: " . $dateDiff2 . " Days</p>"); $days_sum = $days_sum + $dateDiff2; } else { #convert the date format $dateDiff1 = dateDiffInDays($additional_date, $moved_in_date); printf("<p>1st Iteration Difference between " . $additional_date . " and " . $moved_in_date . " is: " . $dateDiff1 . " Days</p>"); $days_sum = $days_sum + $dateDiff1; } $previous = $value; # set the current value, so it will be saved for the next iteration } $i++; } #end foreach $list_values } #endif $list_values #$sum = $sum + 1; #increment our rows echo "<p>Total no of days = " .$days_sum.'</p>'; if ( $days_sum < 1095 ) { echo '<p>Not enough days so loop through list</p>'; $sum = $sum + 1; #increment our rows $flag = 'true'; } } else { echo '<p>Were ok!</p>'; $flag = 'false'; } #we moved in less than 3 years ago, so get history if ( $flag == 'false' ) { return $form; } echo "<p>The sum of array element is = " .$sum.'</p>'; foreach ( $form['fields'] as &$field ) { if ( $field->id == 2 ) { $field->isRequired = true; } if ( $field->id == 3 ) { $_POST['input_3'] = $sum; } } return $form; } From initial testing, this now seems to work!
  5. Hi All, I'm hoping someone can help as I've got myself in a muddle on some code. Basically, the form has a date field (date moved in). If the date entered is over 3 years old, all's ok However, if the date entered is less than 3 years old, the user needs to complete a list field. The list field is essentially a repeater field with a date and address field. If the user adds a date and address and this (plus the original date) is more than 3 years combined history - happy days! If the user adds a date and address and they've still not hit 3 years history, then I need to increase the number of rows (this is handled by another function which works by incrementing a field on the form. As it stands, it works until I need another field to appear i.e. they've entered the first date, then entered a date within the list/repeater field but still not got 3 years worth. I think it's more or less there but seem to have muddled some of the logic (I think/hope!). A fresh pair of eyes would be great: Here's my code: function dateDiffInDays($date1, $date2) { # Calulating the difference in timestamps $diff = strtotime($date2) - strtotime($date1); # 1 day = 24 hours # 24 * 60 * 60 = 86400 seconds return abs(round($diff / 86400)); } add_filter( 'gform_pre_render_2', 'applicant_2_previous_address_history' ); add_filter( 'gform_pre_validation_2', 'applicant_2_previous_address_history' ); function applicant_2_previous_address_history( $form ) { #get the value from the form date input d/m/Y so need to change $get_moved_in_date = rgpost( 'input_1' ); if ( $get_moved_in_date ) { #convert the date format $moved_in_date = date_format(date_create_from_format('d/m/Y', $get_moved_in_date), 'd-m-Y'); #echo "New date format is: ".$moved_in_date. "<br/>"; } #get todays date $today = date("d-m-Y"); #echo "<h3>Today: ".$today."</h3>"; #calculate the difference in days $dateDiff = dateDiffInDays($today, $moved_in_date); #printf("<p>Difference between two dates: " . $dateDiff . " Days</p>"); #check if we moved in less than 3 years ago if ( $dateDiff < 1095 ) { #less than 3 years, so need to loop through the list fields, compare dates and tally totals days if ( $days_sum < 1095 ) { # get the input from the list $list_values = rgpost( 'input_2' ); $i = 0; #use this to get even rows only due to the way data is stored :( $sum = 0; #use this to increment the no. of rows in the list $previous = null; #use this to calc date difference between rows $days_sum = $dateDiff; #set the total number of days. Don't start at 0, start from current date - time at current residence if ( $list_values ) { foreach ( $list_values as $key => $value ){ #get even rows only if($i%2 == 0){ #$sum = $sum + 1; #increment our rows if ( $value ) { #convert the date format $additional_date = date_format(date_create_from_format('d/m/Y', $value), 'd-m-Y'); #echo "<h3>Date: ".$additional_date."</h3>"; } if ( $previous !== null ){ # if it's null, we're in the first loop #convert the date format $previous_date = date_format(date_create_from_format('d/m/Y', $previous), 'd-m-Y'); $dateDiff2 = dateDiffInDays($additional_date, $previous_date); printf("<p>Next Iteration Difference between " . $additional_date . " and " . $previous_date . " is: " . $dateDiff2 . " Days</p>"); $days_sum = $days_sum + $dateDiff2; } else { #convert the date format $dateDiff1 = dateDiffInDays($additional_date, $moved_in_date); printf("<p>1st Iteration Difference between " . $additional_date . " and " . $moved_in_date . " is: " . $dateDiff1 . " Days</p>"); $days_sum = $days_sum + $dateDiff1; } $previous = $value; # set the current value, so it will be saved for the next iteration } $i++; } #end foreach $list_values } #endif $list_values $sum = $sum + 1; #increment our rows echo "<p>Total no of days = " .$days_sum.'</p>'; } #endif $days_sum < 1095 echo '<p>Not enough days so loop through list</p>'; $flag = 'true'; } else { echo '<p>Were ok!</p>'; $flag = 'false'; } #endif $dateDiff < 1095 /* if ( $dateDiff < 1095 ) { $value = 'yes'; } else { $value = 'no'; } */ #we moved in less than 3 years ago, so get history if ( $flag == 'false' ) { return $form; } foreach ( $form['fields'] as &$field ) { if ( $field->id == 2 ) { $field->isRequired = true; } echo "<p>The sum of array element is = " .$sum.'</p>'; if ( $field->id == 3 ) { $_POST['input_3'] = $sum; } } return $form; } Thanks
  6. Hi All, I have a Bootstrap (v4) carousel. It has numerous slides but one slide has a video. For example: <div class="carousel-item" data-interval="10000"> <video id="player" loop> <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4"><br> Your browser does not support the video tag. </video> <div class="carousel-caption d-md-block"> <h3 data-animation="animated flipInX"> This is the caption for slide 4 </h3> </div> </div> What I'm trying to do, is set the video to play only when you're on that slide (active) and pause when you either scroll away (via a click on the carousel arrows/indicators or the carousel interval). Therefore, I will use the event functionality (https://getbootstrap.com/docs/4.0/components/carousel/#events). As I'm using HTML 5 video tags, this is my solution: $('#carousel').carousel().on('slide.bs.carousel',function(){ $('.carousel-item').find('video').each(function(){ this.pause(); }); }); $('#carousel').carousel().on('slide.bs.carousel',function(){ $('.carousel-item active').find('video').each(function(){ this.play(); }); }); Unfortunately, it doesn't seem to work but I can't see why? Am I missing something very obvious?? Many thanks in advanced
  7. Hi All, I've a loop which creates an array as follows: $product_table[] = ['SKU' => $sku, 'Label' => $attribute_name, 'Value' => $term_obj->name ]; I'm then grouping the data by SKU code: #group the products by SKU $group_products = array(); foreach ($product_table as $element) : $group_products[$element['SKU']][] = $element; endforeach; Finally, I output the data: #output the data foreach ($group_products as $itemName => $rows) : echo '<tr>'; #echo '<td>', $element['SKU'], '</td>'; $i=0; foreach ($rows as $row) : $i++; #echo '<td>'. $row["SKU"]. '</td><td>'. $row["Label"]. '</td><td>'. $row["Value"]. '</td>'; if ($i == 1): echo '<td>'. $row["SKU"]. '</td><td>'. $row["Value"]. '</td>'; else: echo '<td>'. $row["Value"]. '</td>'; endif; #echo '<td>'. $row["Value"]. '</td>'; endforeach; echo '</tr>'; endforeach; ?> And looks like: Product code System Pack Quantity XT1CWH System 1 1 x 3m XT2CWH System 2 1 x 3m XT3CWH System 3 1 x 3m This works perfectly fine. However, some products share the same SKU and therefore it causes an issue, like the below: Product code System Pack Quantity XT1CLWH System 1 8 x 3m System 2 8 x 3m System 3 8 x 3m Is there a way I can avoid this, so if perhaps creates the new row but shows the same SKU code? Many thanks
  8. HI @Barand Is it possible to ask one more thing? In your very kind example, you have: $headings = [ 'attribute_pa_colour' => 'Colour', 'attribute_pa_description' => 'Description', 'attribute_pa_material' => 'Material', 'attribute_pa_pack-quantity' => 'Pack Quantity', 'attribute_pa_size' => 'Size', 'attribute_pa_system' => 'System', 'attribute_pa_variation' => 'Variation', 'variation_description' => 'Description', 'sku' => 'SKU', 'variation_id' => 'ID', 'price_html' => 'Price' ]; echo '<pre>', print_r($headings), '</pre>'; And if you print his out, you would see: Array ( [attribute_pa_colour] => Colour [attribute_pa_description] => Description [attribute_pa_material] => Material [attribute_pa_pack-quantity] => Pack Quantity [attribute_pa_size] => Size [attribute_pa_system] => System [attribute_pa_variation] => Variation [variation_description] => Description [sku] => SKU [variation_id] => ID [price_html] => Price ) I thought I'd try and automate this, so have the following code: $attribute_taxonomies = wc_get_attribute_taxonomies(); if ( $attribute_taxonomies ) : $taxonomyOfInterest = array(); foreach ($attribute_taxonomies as $tax=>$tax_value) : $attribute = 'attribute_pa_'.$tax_value->attribute_name; $name = 'pa_'.$tax_value->attribute_name; $label = wc_attribute_label( $name ); $taxonomyOfInterest[] = $attribute.' => '.$label.','; endforeach; endif; array_push($taxonomyOfInterest,"'variation_description' => 'Description',", "'sku' => 'SKU',", "'variation_id' => 'ID',", "'price_html' => 'Price'"); echo '<pre>', print_r($taxonomyOfInterest), '</pre>'; But when I print this out, I get: Array ( [0] => attribute_pa_colour => Colour, [1] => attribute_pa_description => Description, [2] => attribute_pa_material => Material, [3] => attribute_pa_pack-quantity => Pack Quantity, [4] => attribute_pa_size => Size, [5] => attribute_pa_system => System, [6] => attribute_pa_variation => Variation, [7] => 'variation_description' => 'Description', [8] => 'sku' => 'SKU', [9] => 'variation_id' => 'ID', [10] => 'price_html' => 'Price' ) Apologies for the terminology but how do I output this as you have it I guess without an index but arrays always need an index, right?
  9. Well that sounds jolly interesting and not something i've done before. I'll go and look into it Thanks again
  10. Hi @Barand Sorry for the delay replying. Thank you so, so much! That's absolutely bloody brilliant I think I can work out how to remove the bits and bobs I don't need to display (image_id, is_in_stock etc.) Thank you once again!
  11. Hi @Barand Mine looks like this: Array ( [attribute_pa_pack-quantity] => [dimensions] => [dimensions_html] => [image] => [image_id] => [is_in_stock] => [is_purchasable] => [is_sold_individually] => [min_qty] => [sku] => [variation_id] => [variation_is_active] => [variation_is_visible] => [weight_html] => ) I did remove a couple of items from the outset to tidy the initial array output (very first post). I'm sorry, I thought it would make life easier but wonder if I've now muddled the situation in doing so!? Otherwise it was rather lengthy: Array ( [0] => Array ( [attributes] => Array ( [attribute_pa_system] => system-1 [attribute_pa_pack-quantity] => 1-x-3m ) [availability_html] => [backorders_allowed] => [dimensions] => Array ( [length] => [width] => [height] => ) [dimensions_html] => N/A [display_price] => 0 [display_regular_price] => 0 [image] => Array ( [title] => xt1cwh_web_600 [caption] => [url] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png [alt] => [src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-600x600.png [srcset] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png 600w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-400x400.png 400w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-150x150.png 150w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-250x250.png 250w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-120x120.png 120w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-100x100.png 100w [sizes] => (max-width: 600px) 100vw, 600px [full_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png [full_src_w] => 600 [full_src_h] => 600 [gallery_thumbnail_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-100x100.png [gallery_thumbnail_src_w] => 100 [gallery_thumbnail_src_h] => 100 [thumb_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-400x400.png [thumb_src_w] => 400 [thumb_src_h] => 400 [src_w] => 600 [src_h] => 600 ) [image_id] => 719 [is_downloadable] => [is_in_stock] => 1 [is_purchasable] => 1 [is_sold_individually] => no [is_virtual] => [max_qty] => [min_qty] => 1 [price_html] => [sku] => XT1CWH [variation_description] => [variation_id] => 199 [variation_is_active] => 1 [variation_is_visible] => 1 [weight] => [weight_html] => N/A ) [1] => Array ( [attributes] => Array ( [attribute_pa_system] => system-2 [attribute_pa_pack-quantity] => 1-x-3m ) [availability_html] => [backorders_allowed] => [dimensions] => Array ( [length] => [width] => [height] => ) [dimensions_html] => N/A [display_price] => 0 [display_regular_price] => 0 [image] => Array ( [title] => xt1cwh_web_600 [caption] => [url] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png [alt] => [src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-600x600.png [srcset] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png 600w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-400x400.png 400w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-150x150.png 150w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-250x250.png 250w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-120x120.png 120w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-100x100.png 100w [sizes] => (max-width: 600px) 100vw, 600px [full_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png [full_src_w] => 600 [full_src_h] => 600 [gallery_thumbnail_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-100x100.png [gallery_thumbnail_src_w] => 100 [gallery_thumbnail_src_h] => 100 [thumb_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-400x400.png [thumb_src_w] => 400 [thumb_src_h] => 400 [src_w] => 600 [src_h] => 600 ) [image_id] => 719 [is_downloadable] => [is_in_stock] => 1 [is_purchasable] => 1 [is_sold_individually] => no [is_virtual] => [max_qty] => [min_qty] => 1 [price_html] => [sku] => XT2CWH [variation_description] => [variation_id] => 200 [variation_is_active] => 1 [variation_is_visible] => 1 [weight] => [weight_html] => N/A ) [2] => Array ( [attributes] => Array ( [attribute_pa_system] => system-3 [attribute_pa_pack-quantity] => 1-x-3m ) [availability_html] => [backorders_allowed] => [dimensions] => Array ( [length] => [width] => [height] => ) [dimensions_html] => N/A [display_price] => 0 [display_regular_price] => 0 [image] => Array ( [title] => xt1cwh_web_600 [caption] => [url] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png [alt] => [src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-600x600.png [srcset] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png 600w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-400x400.png 400w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-150x150.png 150w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-250x250.png 250w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-120x120.png 120w, https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-100x100.png 100w [sizes] => (max-width: 600px) 100vw, 600px [full_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600.png [full_src_w] => 600 [full_src_h] => 600 [gallery_thumbnail_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-100x100.png [gallery_thumbnail_src_w] => 100 [gallery_thumbnail_src_h] => 100 [thumb_src] => https://www.domain.co.uk/wp-content/uploads/2019/01/xt1cwh_web_600-400x400.png [thumb_src_w] => 400 [thumb_src_h] => 400 [src_w] => 600 [src_h] => 600 ) [image_id] => 719 [is_downloadable] => [is_in_stock] => 1 [is_purchasable] => 1 [is_sold_individually] => no [is_virtual] => [max_qty] => [min_qty] => 1 [price_html] => [sku] => XT3CWH [variation_description] => [variation_id] => 201 [variation_is_active] => 1 [variation_is_visible] => 1 [weight] => [weight_html] => N/A ) ) Apologies if this completely screws things!?
  12. What would cause: Notice: Array to string conversion in... line 93 This refers to echo "<div class='hdg'>{$headings[$h]}</div>$v<br>\n";
  13. Thank you so much @Barand for all of your help!
  14. Thanks @Barand I could do that, then use str replace to tidy it up - not ideal but a workable solution, what do you think? As I say, I could do with a pointer as to how to display the table though if possible? Sorry for asking! As a thought, the heading would always be the first attribute, so in theory would be 'attribute_pa_system'
  15. Thanks @Barand Hmm, I hadn't given that a thought! If i'm honest, i'm struggling a little as to how to output this anyway I hate arrays or they hate me, haven't decided which
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.