• Resolved sejkan

    (@sejkan)


    Hi Dear,
    Idea is to get ajusting price by import element, in my case category.
    Here is the example

    function saleprices($element) {
    	$x = 'Monitor LED';
    	$y = 'PC Notebook Consumer';
    	$z = 'TV LED';
    	if ($element == $x) {
    		echo number_format("120")."<br>";}
    	if (stripos($element, $z) !== false) {
    		echo number_format("125")."<br>";}
    	if (stripos($element, $y) !== false) {
    		echo number_format("130")."<br>";;
    	} else {
    		return;
    	}
    }

    Those echos: 120, 125, 130 I want to place in field REGULAR PRICE.
    But when I try to import like this I get 0.00 prices.

    Could you maybe help me, because this is very practical idea for e-commerce to get pricing by some filter.

    Thank you
    Sejkan

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @sejkan

    There are 2 things to note here:

    • If you’re importing this into the “Regular Price” field, you need to adjust the code so that it only returns the price (do not echo and do not include HTML tags).
    • I’m not sure if you’re doing this, but it’s not possible to use a function in the “Adjust Prices” section, so you’ll need to handle the math in your function that’s used in the Regular Price field.

    Here’s an example of how to return prices based on an import element:

    function my_return_price( $element ) {
        $map = array(
            'Monitor LED' => 120,
            'PC Notebook Consumer' => 125,
            'TV LED' => 130
        );
    
        return ( array_key_exists( $element, $map ) ) ? $map[ $element ] : 0;
    }

    You’d need to pass the price and element to it like so (make sure to change the element to the one from your import):

    [my_return_price({element[1]})]

    Or, if you’re looking to *adjust* the price, you could use a function like this:

    function my_adjust_price( $price, $element ) {
        $adjust_map = array(
            'Monitor LED' => 1.20,
            'PC Notebook Consumer' => 1.25,
            'TV LED' => 1.30
        );
    
        return ( array_key_exists( $element, $adjust_map ) ) ? ( $price * $adjust_map[ $element ] ) : $price;
    }

    Which would require you to pass both the price and the adjust element:

    [my_adjust_price({price[1]},{element[1]})]

    Thread Starter sejkan

    (@sejkan)

    Thank you a lot,
    It is very usful.

    But if we use only:

    [my_adjust_price({price[1]},{element[1]})]

    The problem or the point is what to do when element is not found in above case.

            'Monitor LED' => 1.20,
             'PC Notebook Consumer' => 1.25,
             'TV LED' => 1.30

    What to do if we get other element not found above.
    Thank you.

    I think this is very usful to arrange price by some filter.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @sejkan

    If the element isn’t found then it returns the price with no adjustment. Keep in mind that this is only an example snippet and you’ll almost certainly have to adjust it to make it work exactly as desired.

    Thread Starter sejkan

    (@sejkan)

    Thank you,
    Ok I figure out how to implement this on regular price. Thank you a lot.

    Is there any whey to import sale price to, but to skip import of sale price if it is higher or same as regular price.

    Thank you

    Thread Starter sejkan

    (@sejkan)

    Solved too, just return null;
    : null;

    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adjust price by category / import element’ is closed to new replies.