foreach

Show hide payment gateways based on backordered items in Woocommerce

倖福魔咒の 提交于 2020-06-26 14:05:32
问题 I'm need to hide paypal when there's any backordered item on cart or hide cod if there's not any item to be backordered. My problem here is if there's a item that's backorder together with one that is not, I end up whitout a payment processor add_filter( 'woocommerce_available_payment_gateways', 'backordered_items_hide_cod', 90, 1 ); function backordered_items_hide_cod( $available_gateways ) { // Only on front end if ( is_admin() ) return; // Loop through cart items foreach( WC()->cart->get

PHP - Remove duplicates with foreach?

余生颓废 提交于 2020-06-25 04:37:06
问题 I have a array of page numbers: foreach($elements as $el) { $pageno = $el->getAttribute("pageno"); echo $pageno ; } Sadly it contains duplicates. I tried the follow code but it won't return a thing: foreach(array_unique($elements) as $el) { $pageno = $el->getAttribute("pageno"); echo $pageno ; } How to remove the duplicate page numbers? Thanks in advance :) 回答1: Since I do not have your data structure, I am providing a generic solution. This can be optimized if we know the structure of

PHP Casting Variable as Object type in foreach Loop

断了今生、忘了曾经 提交于 2020-06-24 04:15:28
问题 Within the following code, $quiz_object->personalities contains an array of Personality objects. // Loop through each personality that exists for the quiz foreach($quiz_object->personalities AS $existing_personality) { // Show all of the existing personalities echo $existing_personality->GetQuizMakerPersonalityHTML(); } How do I "cast" (I think that's the right word) my variable $existing_personality within the foreach loop as the object type? I wish to do this so that when I type $existing

How to dynamically bind params in mysqli prepared statement?

≡放荡痞女 提交于 2020-06-22 12:47:10
问题 I'm trying to create a function for my project. I would like it to handle all the check functions. What I mean with that is before you start inserting a row in your database you check if a row exists with that email address. To use this function dynamically it needs to be flexible. So I did put my variables in an array, but mysqli_stmt_bind_param can't handle arrays. As a solution, I tried making a foreach loop. The query: $sql = "SELECT users_id, users_email FROM users WHERE users_id = ? AND

forEach() iterates too fast with ASYNC AWAIT - Skipping data

为君一笑 提交于 2020-06-17 09:56:27
问题 I am re-writing my website and am trying to import my members from array of JSON objects. Each object represents a band that the user has uploaded. So I wrote a quick file that works with the list and my new database / authentication system, auth0. As outline in the comments below... First I Request an access token so I can create an account for each member using Auth0. Then I iterate through my array of objects representing bands. For each band object I have the code do a few things... First

edit out portions of a XML file inside an XSL `for-each` loop

大兔子大兔子 提交于 2020-06-17 09:38:28
问题 I am trying to edit out portions of a XML file inside an XSL for-each loop. I have an XML file with several templates, and the XSL file has a for-each loop to display all of them. My goal was to eliminate certain templates from displaying within the XSL for-each loop by targeting individual templateId's inside the node. This is the code: XML <component typeCode="SEWS" contextConductionInd="true"> <section> <templateId root="2.12.840.1.103883.13.20.23.2.68"/> <code code="58907-0" codeSystem="1

ForEach and GeometryReader: variable height for children?

只谈情不闲聊 提交于 2020-06-17 08:05:49
问题 I have following example: import SwiftUI struct TestSO: View { @State var cards = [ Card(title: "short title text", subtitle: "short title example"), Card(title: "medium title text text text text text", subtitle: "medium title example"), Card(title: "long title text text text text text text text text text text text text text text text text text", subtitle: "long title example"), Card(title: "medium title text text text text text", subtitle: "medium title example"), Card(title: "short title

Access Violation: Cannot apply indexing with [] to an expression of type 'object'

一世执手 提交于 2020-06-17 03:09:07
问题 I have the following variable: _Data. The variable contains the following info: _Data Variable How can i access the message field? I tried _Data["messages"][0] - but it not wokring. I recieved the following error: Cannot apply indexing with [] to an expression of type 'object' What am i doing wrong? Thanks. 回答1: What am i doing wrong? _Data["messages"] is returning type object . You need to cast it to List<string> or IList<string> in order to use an indexer. var indexable = _Data["messages"]

Extract lines matching a pattern from all text files in a folder to a single output file

拈花ヽ惹草 提交于 2020-06-10 15:25:53
问题 I am trying to extract each line starting with "%%" in all files in a folder and then copy those lines to a separate text file. Currently using this code in PowerShell code, but I am not getting any results. $files = Get-ChildItem "folder" -Filter *.txt foreach ($file in $files) { if ($_ -like "*%%*") { Set-Content "Output.txt" } } 回答1: I think that mklement0's suggestion to use Select-String is the way to go. Adding to his answer, you can pipe the output of Get-ChildItem into the Select

Extract lines matching a pattern from all text files in a folder to a single output file

做~自己de王妃 提交于 2020-06-10 15:24:51
问题 I am trying to extract each line starting with "%%" in all files in a folder and then copy those lines to a separate text file. Currently using this code in PowerShell code, but I am not getting any results. $files = Get-ChildItem "folder" -Filter *.txt foreach ($file in $files) { if ($_ -like "*%%*") { Set-Content "Output.txt" } } 回答1: I think that mklement0's suggestion to use Select-String is the way to go. Adding to his answer, you can pipe the output of Get-ChildItem into the Select