Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Everything posted by jarvis

  1. Hi @cyberRobot It's Wordpress/WooCommerce so it's simply a function/hook: function prg_woocommerce_checkout_fields( $checkout_fields = array() ) { $checkout_fields['order']['categories'] = array( 'type' => 'select', 'class' => array('my-field-class form-row-wide'), 'label' => __('Categories', 'woocommerce'), 'placeholder' => _x('', 'placeholder', 'woocommerce'), 'required' => false, 'clear' => false, 'options' => array_values($category_str) ); return $checkout_fields; } If I manually add the option: 'options' => array( 'eat-meat' => __('I eat meat', 'woocommerce' ), 'not-meat' => __('Meat is gross', 'woocommerce' ) ) Then the drop down creates correctly: <option value="eat-meat">I eat meat</option> <option value="not-meat">Meat is gross</option> But once I try to make it dynamic by passing values from elsewhere, it just doesn't quite display the right output Does that help?
  2. Ok, I've managed to get somewhere but struggling with one part now. So I now have: $categories = get_field( 'categories', 'options' ); $choices = array(); if ( is_array( $categories ) ) { $category_str = array(); foreach ( $categories as $category ) { $category['value']; $category['label']; $category_str[$category['value']] = $category['label']; } } $checkout_fields['order']['categories'] = array( 'type' => 'select', 'class' => array('my-field-class form-row-wide'), 'label' => __('Food options', 'woocommerce'), 'placeholder' => _x('', 'placeholder', 'woocommerce'), 'required' => false, 'clear' => false, 'options' => array_values($category_str) ); If I use print_r($category_str); I see the following: Array ( [a] => A [b] => B [c] => C ) Yet if I view the drop down it shows: <option value="0">A</option> <option value="1">B</option> <option value="2">C</option> So how do I get the value to be the value from the first array? So it's like this: <option value="a">A</option> <option value="b">B</option> <option value="c">C</option> Thanks
  3. Hi, Am hoping someone can help/point me in the right direction! I have the following code: $checkout_fields['order']['categories'] = array( 'type' => 'select', 'class' => array('my-field-class form-row-wide'), 'label' => __('Food options', 'woocommerce'), 'placeholder' => _x('', 'placeholder', 'woocommerce'), 'required' => false, 'clear' => false, 'options' => array( 'eat-meat' => __('I eat maet', 'woocommerce' ), 'not-meat' => __('Meat is gross', 'woocommerce' ) ) ); However, I'd like to make the options part dynamic and therefore grab the values from elsewhere. So I then have this code: $categories = get_field( 'categories', 'options' ); $choices = array(); if ( is_array( $categories ) ) { $category_str = array(); foreach ( $categories as $category ) { #echo $category['value']; #echo $category['label']; $category['value']; $category['label']; $category_str[] = $category['value'].$category['label']; } $result = implode(",",$category_str); echo $result; } My issue is I'm not sure on the best way to amalgamate the two? Can someone help?
  4. I sussed it as soon as I clicked submit! My apologies but thank you once again for your time and assistance!
  5. Hi, Apologies if this is a basic question but either I've misunderstood or I'm being daft In one function I have: function create_coupon() { $unique_coupon_code = $coupon_name.'-'.$date; #concatenate the two return $unique_coupon_code; } Then in my second function I try to get that variable ($unique_coupon_code) to use again: function use_coupon() { echo $unique_coupon_code; } But it returns blank? However, if I echo $unique_coupon_code; in the first function, it does show a value What am I doing wrong? Thanks
  6. Apologies @requinix that did work - I was being a numpty!
  7. Thanks @requinix When I try I get array For testing, I do know the coupon name but won't going forward (that's my next task)
  8. Hi, Apologies If I've got the title wrong but I'm trying to obtain a value from an array, however, it's an object (?) Array ( [test] => WC_Coupon Object ( [code] => test [id] => 1529 [exists] => 1 [discount_type] => percent_product [coupon_amount] => 10 [individual_use] => yes [product_ids] => Array I need to get coupon_amount I thought I could use $my_coupon[0]->coupon_amount; but believe I've confused myself or misunderstood! Any advice is gratefully received! Thanks
  9. Aaaaah! Gotcha!! Working perfectly now - thank you. More so for not giving the code and making me do the work :-)
  10. I can't see for looking. Have I just put the AND and OR the wrong way round? But then the AND has higher priority which is why I put it first. That said, I'd it has a higher priority, then I guess it could go after the OR?
  11. Thanks requinix Yes, sadly it's Wordpress and stores data that way - made for an interesting day so far! Ok, I will look to amend the query but last time i tried if broke it lol. It looked like this: WHERE ( a1.meta_key = '$siteID' AND a1.meta_value NOT LIKE 'a:1:{s:12:"shop_manager";b:1;}' } AND { a2.meta_key = '$siteID' AND a2.meta_value = 'a:1:{s:10:"subscriber";b:1;}' ) AND ( a3.meta_key = 'q1' AND a3.meta_value REGEXP '$q1_regex' OR a4.meta_key = 'q2' AND a4.meta_value REGEXP '$q2_regex' OR a5.meta_key = 'q3' AND a5.meta_value REGEXP '$q3_regex' ) But think that may be wrong also!?
  12. Hi, I think I'm missing the obvious, so turned to here for some assistance! I have the following query: SELECT DISTINCT a1.user_id FROM $wpdb->usermeta a1 INNER JOIN $wpdb->usermeta a2 ON a1.user_id = a2.user_id INNER JOIN $wpdb->usermeta a3 ON a1.user_id = a3.user_id INNER JOIN $wpdb->usermeta a4 ON a1.user_id = a4.user_id INNER JOIN $wpdb->usermeta a5 ON a1.user_id = a5.user_id WHERE ( a1.meta_key = 'q1' AND a1.meta_value REGEXP '$q1_regex' ) OR ( a2.meta_key = 'q2' AND a2.meta_value REGEXP '$q2_regex' ) OR ( a3.meta_key = 'q3' AND a3.meta_value REGEXP '$q3_regex' ) AND ( a4.meta_key = '$siteID' AND a4.meta_value NOT LIKE 'a:1:{s:12:\"shop_manager\";b:1;}' ) AND ( a5.meta_key = '$siteID' AND a5.meta_value = 'a:1:{s:10:\"subscriber\";b:1;}' ) It returns results (which is a good start). However, it also returns some results that shouldn't be there. In this example. $siteID = 'table_99_capabilities'; For example. It returns the following user IDs 61 64 65 Yet I know the following: 61 = is a customer, so fails on the last part of the query (AND a5.meta_value = 'a:1:{s:10:\"subscriber\";b:1;}') 64 & 65 fail as they have a siteID of table_66_capabilities I'm hoping this is enough info and clearly explained Any help is much appreciated Thanks for your time
  13. Thanks, it now works! Apologies
  14. Thanks Jacques1 I get what you're saying but can't see how I can get around it? Perhaps you could elaborate? Give me a clue?? I appreciate your time and help and am keen to get this working, so you assistance is very helpful - thanks
  15. 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?
  16. 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 )
  17. 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?
  18. 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
  19. 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?
  20. @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?
  21. 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!)
  22. 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
  23. Apologies, than you cyberRobot, that's much appreciated
  24. 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?
  25. Thanks again for the reply. Yes, I'd like to keep the HTML formatting
×
×
  • 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.