Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Everything posted by jarvis

  1. Thanks Jacques1 Ok, for simplistic terms, if I did: if ( ($advert_category == $page_id) && $advert_page == ''): echo 'cat ad'; $cat_banner[]=$order->id; endif; if ( $advert_category == '' && ($advert_page == $page_id) ): echo 'page ad'; $page_banner[]=$order->id; endif; if ( $advert_category == '' && ($advert_page == '') ): echo 'no matches - random'; $random_banner[]=$order->id; endif; It still returns: Array ( ) Array ( ) Array ( [0] => 1652 ) Surely this method doesn't overwrite the array as it's 3 different arrays?
  2. Thanks @Jacques1 But I tried $cat_banner = array(); $page_banner = array(); $random_banner = array(); foreach( $order->get_items() as $item ): $advert_url = $item['Platinum Advert URL']; #echo 'Ad URL: '.$advert_url.'<br/>'; $advert = $item['Platinum Advert']; #echo 'Ad: '.$advert.'<br/>'; $advert_category = $item['Advert Category']; #echo 'Advert Category: '.$advert_category.'<br/>'; $advert_page = $item['Advert Page']; echo 'Advert Page: '.$advert_page.'<br/>'; echo 'ID: '.$order->id.'<br/>'; #if the below matches the ID passed via ajax, add the order ID to an array if ( ($advert_category == $page_id) && $advert_page == ''): echo 'cat ad'; $cat_banner[]=$order->id; elseif ( $advert_category == '' && ($advert_page == $page_id) ): echo 'page ad'; $page_banner[]=$order->id; else: echo 'no matches - random'; $random_banner[]=$order->id; endif; echo '<hr/>'; endforeach; endforeach; } } ?> <hr /> <pre><?php print_r($cat_banner); #debug ?></pre> <pre><?php print_r($page_banner); #debug ?></pre> <pre><?php print_r($random_banner); #debug ?></pre> And that still only shows 1 ID I thought I could go this route, then merge the arrays but still only got the 1 result: Array ( ) Array ( ) Array ( [0] => 1652 )
  3. Hi @Kicken, The conditionals are used to meet other criteria, so depending which page or category of the site you're on, Basically, the order contains a banner ad that has been assigned to a page or a category or may not have been assigned at all The code detects what page or category of the site you're on. The conditional then checks all orders with that page ID against the page you're on. If it matches, it passes all order IDs to an array. It does the same for categories. If none match then it retrieves all orders where a page or category hasn't been assigned. Once I have the order IDs, I then randomise them and display the banner ad from the order ID I genuinely don't think any other code would help. However, here it is: $top_adverts = WC_Subscriptions_Manager::get_all_users_subscriptions(); ?><pre><?php #print_r($top_adverts); ?></pre><?php foreach ($top_adverts as $key => $value) { if ( $top_adverts[$key]["status"]=="active" && ($top_adverts[$key]["product_id"]=="21" || $top_adverts[$key]["product_id"]=="1285" || $top_adverts[$key]["product_id"]=="1639" || $top_adverts[$key]["product_id"]=="1642" )) { #get the order number $order_id = $top_adverts[$key]["order_id"]; #echo 'Order ID: '.$order_id.'<br/>'; $top_ad_args = array( 'post_type' => 'shop_order', 'post_status' => 'publish', 'posts_per_page' => '1', 'p'=>$order_id, 'tax_query' => array( array( 'taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array('completed') #completed ) ) ); $top_orders=get_posts($top_ad_args); #print_r($top_orders); foreach($top_orders as $order): $order_id = $order->ID; $order = new WC_Order($order_id); ?><pre><?php #print_r($order); ?></pre><?php $active_banner = array(); foreach( $order->get_items() as $item ): $advert_url = $item['Platinum Advert URL']; #echo 'Ad URL: '.$advert_url.'<br/>'; $advert = $item['Platinum Advert']; #echo 'Ad: '.$advert.'<br/>'; $advert_category = $item['Advert Category']; #echo 'Advert Category: '.$advert_category.'<br/>'; $advert_page = $item['Advert Page']; echo 'Advert Page: '.$advert_page.'<br/>'; echo 'ID: '.$order->id.'<br/>'; #if the below matches the ID passed via ajax, add the order ID to an array if ( ($advert_category == $page_id) && $advert_page == ''): echo 'cat ad'; $active_banner[]=$order->id; elseif ( $advert_category == '' && ($advert_page == $page_id) ): echo 'page ad'; $active_banner[]=$order->id; else: echo 'no matches - random'; $active_banner[]=$order->id; endif; echo '<hr/>'; endforeach; endforeach; } } ?> <hr /> <pre><?php print_r($active_banner); #debug ?></pre> I just can't see why if the code displays the IDs, it's not showing them in the array? Does that help?
  4. Hi, I really hope someone can help! I have the following code: if ( ($advert_category == $page_id) && $advert_page == ''): echo 'cat ad'; $active_banner[]=$order->id; elseif ( $advert_category == '' && ($advert_page == $page_id) ): echo 'page ad'; $active_banner[]=$order->id; else: echo 'no matches - random'; $active_banner[]=$order->id; endif; Basically, depending on the criteria, it should add an order ID to an array. If I output the info, I know that that ID's should go into an array as I can see: order ID: 21495 page ad order ID: 1652 no matches - random However, when I dump out the main array, I only see one ID: Array ( [0] => 1652 ) Can someone explain why this would be? Thanks
  5. I guess if the code above means i don't need to convert to a string, then put the string back into the array then I think we're all good apologies if I've confused the matter All I want to do is automate the process so instead of typing everything into $categories = array ('manually adding each category'); I thought if I loop the categories I can make this automatically happen I've a feeling I got myself in a muddle and therefore, if I set up my loop and add each value into the $categories array, this will do the same as the line of code above?
  6. @ginerjm - its a wordpress/woocommerce term @cyberRobot - if I go the route as per my code a minute ago, shouldnt this negate the need to use implode?
  7. Thank you all for you comments @Barand, I think that was the missing piece I needed. So if I've understood you correctly, I could just do this: $categories = array(); foreach($wctTerms as $wctTerm) { $categories[] = $wctTerm->slug; } Would that work? I think I've over complicated something very simple (the usual!)
  8. Hi All, I think I'm being pretty daft! I currently have the following: $categories = array( 'cat 1', 'cat 2', 'cat 3'); This is fine but the issue is it required someone manually entering the values. I therefore setup a loop which gets all my categories: $subcats = array(); foreach($wctTerms as $wctTerm) { $subcats[] = $wctTerm->slug; } I can then use: $comma_separated = implode (", ", $subcats); Which spits out what I need: cat 1, cat 2, cat 3 etc. But how do I get this back into the original $categories part. I thought: $categories = array( $comma_separated ); But that doesn't work Feeling pretty daft right now! Any pointers much appreciated
  9. Apologies, than you cyberRobot, that's much appreciated
  10. So something like this: function limit_words($string, $word_limit) { #$words = explode(" ",$string); $words = preg_split('/\s+/', $string); #echo '<pre>' . print_r($words, true) . '</pre>'; #echo '<pre>' .print_r(array_filter($words)) . '</pre>'; $filter = array_filter($words); #return implode(" ",array_splice($words,0,$word_limit)); return implode(" ",array_splice($filter,0,$word_limit)); } Although that doesn't seem to work either?
  11. Thanks again for the reply. Yes, I'd like to keep the HTML formatting
  12. Thank you cyberRobot! Is there a way around this without compromise to outputting the HTML?
  13. Hi, I'm going mad and in desperation am reaching out for some help. I have a site that outputs a snippet of text (30 words) from a full description (string). The description includes HTML for formatting, which I need to keep in the snippet. My issue is that the snippet never returns 30 words! Below is my code: function limit_words($string, $word_limit) { #$words = explode(" ",$string); $words = preg_split('/\s+/', $string); return implode(" ",array_splice($words,0,$word_limit)); } function limit_words2($string, $word_limit) { $words = explode(" ",$string); #$words = preg_split('/\s+/', $string); return implode(" ",array_splice($words,0,$word_limit)); } $content = " <p><p><strong>LOCATION</strong><br />Centrally located in Kent just of the High Street.</p> <p><strong>ACCOMMODATION</strong><br />231 sq ft.</p> <p><strong>AMENITIES</strong><br />Entry Phone System<br /> Central Heating<br /> Car Parking</p> <p><strong>TERMS</strong><br />A new lease for a term to be agreed.</p> <p><strong>OUTGOINGS</strong><br />To be assessed.</p> <p><strong>VAT</strong><br />All prices and rents are quoted exclusive of VAT. Any intending purchaser or lessee must satisfy themselves as to the incidence of VAT in respect of any transaction.</p> <p><strong>LEGAL COSTS</strong><br />Each party to be responsible for their own legal costs.</p> <p><strong>SERVICE CHARGE</strong><br />Tenant to be responsible for a proportion of costs towards insurance, maintenance and repairs.</p> </p> "; $content2 = " <p><p><strong>LOCATION</strong><br />A shop/office premises to let in Kent, close to NatWest, Holland & Barrett and Fat Face.</p> <p><strong>DESCRIPTION</strong><br />A shop/office premises to let in Kent, close to NatWest, Holland & Barrett and Fat Face.</p> <p><strong>ACCOMMODATION</strong><br />Approximately 159 sq ft. </p> <p><strong>AMENITIES</strong><br />Attractive display window<br /> Laminate floor<br /> Display lighting<br /> Alarm</p> <p><strong>TERMS</strong><br />Easy in easy out terms.</p> <p><strong>OUTGOINGS</strong><br />We understand that the current rateable value is £2550.<br /> Current UBR – 48.2p in £<br /> Small business relief may be available.</p> <p><strong>VAT</strong><br />All prices and rents are quoted exclusive of VAT. Any intending purchaser or lessee must satisfy themselves as to the incidence of VAT in respect of any transaction. The rent is also subject to VAT.</p> <p><strong>LEGAL COSTS</strong><br />Each party responsible for their own legal costs.</p> <p><strong>SERVICE CHARGE</strong><br />Insurance currently £223.32 per annum plus VAT.</p> </p> "; echo limit_words($content,30); echo '<hr>'; echo limit_words($content2,30); echo '<hr>'; echo limit_words2($content,30); echo '<hr>'; echo limit_words2($content2,30); What on earth am I doing wrong? Any help is much appreciated!
  14. Hi All, I'm hoping someone can help! I've got multiple XML files each start and end with a <property> tag I'm trying to merge all files and the following works in terms of merging the files: #Create an array of all file names $files = array(); #Create a function to combine all XML docs function combineXML($file) { global $xmlstr; $xml = simplexml_load_file($file); foreach($xml as $element) $xmlstr .= $element->asXML(); } #Create an XML file for each result foreach ($posts as $post){ $file_name = $post->vebraid.'.xml'; $myfile = fopen($file_name, "w") or die("Unable to open file!"); $content = $post->xml; fwrite($myfile, $content); #Add filename into array of all file names $path = get_stylesheet_directory_uri(); $directory = '/xml/'; $files[]=$path.$directory.$post->vebraid.'.xml'; #Concatenates two or more XML files by creating a string representation of XML elements then reloading string as XML $xmlstr = '<property>'; foreach ($files as $file) combineXML($file); $xmlstr .= '</property>'; #Convert string to XML for further processing $xml = simplexml_load_string($xmlstr); $bytes = file_put_contents("combined.xml", $xml->asXML()); } However, I need to differentiate between each file within the new combined.xml file, ideally adding <prop_detail> around each merged file, for example: <property> <prop_detail> first file contents </prop_detail> <prop_detail> second file contents </prop_detail> <prop_detail> third file contents </prop_detail> </property> I simply can't see how I can introduce this new element Any help is very much appreciated!
  15. Thanks @maxxd, $wpdb->update( $table, $data, $where ); should be commented out - it's for my ref only. Sorry! Thanks for your help though, I think I may leave them as separate queries to run as easier to work with etc.
  16. Hi All, I'm possibly being daft (I blame the heat!). I have the following 2 statements: #Update Site Title $wpdb->show_errors(); $wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->options, array( 'option_name' => 'blogname', 'option_value' => 'NEW BLOG NAME', 'autoload' => 'yes' ), array( "option_id", $option_id ) ); $wpdb->print_error(); var_dump( $wpdb->last_query ); #Update Site Wide Description $wpdb->show_errors(); $wpdb->update( $table, $data, $where ); $wpdb->update( $wpdb->options, array( 'option_name' => 'blogdescription', 'option_value' => 'MAIN SITE DESCRIPTION GOES HERE', 'autoload' => 'yes' ), array( "option_id", $option_id ) ); $wpdb->print_error(); var_dump( $wpdb->last_query ); As both reside in the same table (options), do I have to run them as separate statements OR is there a way I can run both in one statement? Thanks
  17. Scrap that, I worked it out when I posted and tidied the above - sorry!
  18. Hi, I'm struggling with something which I thought would be very simple. I'm using date_diff to compare to dates, I then wish to run an if statement depending on the difference in days. For example: <?php $date1=date_create("2013-03-15"); $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days"); ?> The output is therefore: "+272 days" ; So why does this not work: $test = $diff->format("%a"); echo $test.'<br>'; if ($test > '250'){ echo 'whoa'; } Am I missing something? Thanks
  19. Thanks @gizmola Apologies for not being clear! Yes, the column with the serialized data is in option_value I need to update 2 parts: 1) email 2) receiver_email The data will not be a constant (i.e. a different email address) but the field name (email and receiver_email) will be constant. The new value will be from $newEmail Does that help? Thanks again
  20. Hi All, I'm really hoping someone can help! I have a table which contains serialised data. I need to run a query which updates 2 elements The table structure is this: `options` (`option_id`, `option_name`, `option_value`, `autoload`) Then within this I have as an example: (1619, 'woocommerce_paypal_settings', ' a:18:{ s:7:"enabled"; s:2:"no"; s:5:"title"; s:6:"PayPal"; s:11:"description"; s:85:"Pay via PayPal; you can pay with your credit card if you don''t have a PayPal account."; s:5:"email"; s:35:"your@email.com"; s:8:"testmode"; s:3:"yes"; s:5:"debug"; s:2:"no"; s:8:"advanced"; s:0:""; s:14:"receiver_email"; s:35:"your@email.com"; s:14:"identity_token"; s:0:""; I need to update email and receiver_email with a new value supplied ($newEmail) I'm not 100% sure but think you have to unserialise, make the amend and re-serialise is that correct? Or is there a better way of handling this? Thanks in advanced
  21. Hi All, I hope someone can help. I currently have the following code: $all_categories = get_categories( $args ); // display a message as the first option $choices = array(array('text' => 'Please Select A Category', 'value' => 0 )); foreach ($all_categories as $cat){ if($cat->category_parent == 0){ $category_id = $cat->term_id; $choices[] = array( 'text' => $cat->name, 'value' => $cat->slug, 'isSelected' => false ); } } $field['choices'] = $choices; As you can see, it loops through a list of results and this is used to construct a drop down The issue I've got, it only returns the top level of categories. In order to get categories and sub categories I need to alter the code to the following: $all_categories = get_categories( $args ); foreach ($all_categories as $cat) { if($cat->category_parent == 0) { $category_id = $cat->term_id; echo $cat->name .'<br/>'; $args2 = array( 'taxonomy' => $taxonomy, 'child_of' => 0, 'parent' => $category_id, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); $sub_cats = get_categories( $args2 ); if($sub_cats) { foreach($sub_cats as $sub_category) { echo ' '.$sub_category->name.'<br/>'; } } } } However, I can't then add the code I need as I now have 2 foreach loops Is there anyway around this?
  22. Hi Jacques1, That's a fair point but I guess it's the way the wordpress tables handle the info as each wordpress post can have multiple meta hence why I need to search on both those criteria
  23. Hi All, I have the following SQL (which is from Wordpress/WooCommerce): SELECT $wpdb->woocommerce_order_items.order_item_id, $wpdb->woocommerce_order_items.order_id, $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value, $wpdb->users.ID, $wpdb->users.user_nicename, $wpdb->woocommerce_order_itemmeta.meta_key, $wpdb->woocommerce_order_itemmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->users ON $wpdb->postmeta.meta_value = $wpdb->users.ID INNER JOIN $wpdb->woocommerce_order_items ON $wpdb->postmeta.post_id = $wpdb->woocommerce_order_items.order_id INNER JOIN $wpdb->woocommerce_order_itemmeta ON $wpdb->woocommerce_order_items.order_item_id = $wpdb->woocommerce_order_itemmeta.order_item_id WHERE $wpdb->postmeta.meta_key = '_customer_user' AND $wpdb->woocommerce_order_itemmeta.meta_key = '_wcs_migrated_subscription_status' AND $wpdb->woocommerce_order_itemmeta.meta_value = 'active' What I need to do is add another 2 lines at the bottom like so: AND $wpdb->woocommerce_order_itemmeta.meta_key = '_product_id' AND $wpdb->woocommerce_order_itemmeta.meta_value = '20' However, simply adding those 2 lines returns no results, removing those lines returns results yet I know it should have something! Any help is much appreciated
  24. Thanks again maxxd However, as the php creates content within the javascript file, I don't think I can move the inline script into its own javascript file - as far as I know!?
×
×
  • 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.