• Resolved nafalan

    (@nafalan)


    I’m trying to import products and apply a markup to them based on the category it is a part of.

    This is the Code I have in the regular price box:

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

    The code I have in the function editor is as follows:

    <?php
    function my_adjust_price( $price, $element = '' ) {
        $adjust_map = array(
            'Monitors'          => 5.20,
            'Networking' => 1.95,
            'Graphics Cards'               => 4.30
        );
    
        return ( array_key_exists( $element, $adjust_map ) ) ? ( number_format( $price * $adjust_map[ $element ], 2 ) ) : $price;
    }
    ?>

    I’ve followed this link and the solution provided but I’m still having problems and the price doesn’t get adjusted it just returns as blank not zero just straight blank.

    • This topic was modified 2 years, 5 months ago by nafalan.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @nafalan,

    Since inline PHP functions are a pro feature and we can only help with our free plugins on this forum, please contact us at http://www.wpallimport.com/support/ for assistance. Keep in mind that we won’t be able to help with the custom code itself, but we can check to make sure the function is being used correctly in the import template.

    Thread Starter nafalan

    (@nafalan)

    I’ve just submitted a ticket and I hope we can find a solution for this.

    Thread Starter nafalan

    (@nafalan)

    for anyone how comes across this post the support guy (Diego) gave me an incredible solution and was crazy fast.

    the solution is below:

    this goes into the regular price section for WooCommerce WP import. Just remember to put your references from your CSV/XML for price and category by dragging and dropping it.

    [example_adjust_price_by_category({cost[1]},{category[1]})]

    this goes into the function editor (add categories by copy and pasting a section after the break)

    function example_adjust_price_by_category ($price, $category = '') {
    
    	if ( !empty($category) ) {
    
    		switch($category) {
    			case 'Shoes':
    				return $price * 1.2;
    				break;
    			case 'Jackets':
    				return $price * 1.4;
    				break;
    			default:
    				// No category specified, so we return nothing
    				break;
    		}
    
    	}
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Product markup based on category’ is closed to new replies.