Wp All Imports PHP Function Editor change value of

2019-09-12 15:23发布

I am having trouble changing the value of an xml node in wp all imports for Wordpress Woocommerce. The xml feed lists Green, Amber, Red and Blue as it's stock levels. I need to change this to 12, 3, 0 and 0 for each value . I have looked at using simple xml but not sure this applies to this method. The function editor holds the custom php in a wordpress file much like the custom php file you would use in a child theme.

I have looked at this example in the link below but not sure how to apply it to what i am trying to acheive change value of xml node with simpleXML

This is the code i have got so far in the function editor

<?php
function ae_stock_change($x) {
if (StockLevel == "Green")
    $x = 12;
elseif (StockLevel == "Amber")
    $x = 3;
else $x = 0;
return $x;

?>

and this is the xml file example

<StockFile>
<MatrixID>1533</MatrixID>
<Brand>Bassaya</Brand>
<ProductCode>basagnez</ProductCode>
<ShortDescription>Bassaya Agnez BlackL/XL</ShortDescription>
<Range>Bassaya Agnez</Range>
<StockLevel>Red</StockLevel>
<Colour>Black</Colour>
<Size>L/XL</Size>
<SupplyType>Discontinued</SupplyType>
<Trade>14.24</Trade>
<RRP>29.99</RRP>
<Image1Name>basagnez.jpg</Image1Name>
<Image2Name/>
<Image3Name/>
<TypeName>Chemise</TypeName>
</StockFile>

1条回答
再贱就再见
2楼-- · 2019-09-12 16:01

Here we go i already did face the same problem and have perfect solution for you :),

You can go to your theme's functions.php file and make your function :

function ae_stock_change($StockLevel) {
if ($StockLevel == "Green"):
    $x = 12;
elseif ($StockLevel == "Amber"):
    $x = 3;
else: 
   $x = 0;
endif;
return $x;
}

And then where in inputs you assign the wp all import variables such as :

{MatrixID[1]} 

your should wrap it inside an function call like this:

[ae_stock_change({MatrixID[1]})] 

and when it will start executing the script for importing the things it will go through the function you assigned inside the input and filter it through your function :)

查看更多
登录 后发表回答