WP-Lister for Amazon API – Hooks and filters

If you are a developer writing a plugin or theme for WP-Lister for Amazon, you might find the following filters and actions hooks useful.

Note: This documentation is work in progress and doesn’t cover all available hooks yet.

If you want us to add a specific hook to help in your particular use case, don’t hesitate to contact us. We appreciate all suggestions and will usually implement your request in the next update.

wpla_product_has_changed

Mark a product as changed in WP-Lister. Use this if you need to emulate how WP-Lister behaves when a product is updated manually in WooCommerce: The profile will be reapplied and the listing status is set to changed, which means the changes will be submitted to Amazon on the next cron job run. So if your cron job runs every 5 minutes, a listing feed will be submitted within 5 minutes – but keep in mind that Amazon might take longer than that to actually process your feed (usually less than 30 minutes though).

Usage

do_action('wpla_product_has_changed', $post_id );

wpla_filter_listing_feed_column

This is a general purpose filter which allows you to modify any column in a listing feed. The example below demonstrates how to force the price column to be left empty – in case you prefer to manage Amazon prices on Seller Central only. Available since version 0.9.1.5.

Usage

add_filter( 'wpla_filter_listing_feed_column', 'my_custom_amazon_feed_filter' , 10, 6 );
function my_custom_amazon_feed_filter( $value, $column, $item, $product, $profile, $template_type ) {

	// force empty price column
	if ( 'price' == $column ) {
	    $value = '';
	}

	// force empty sale price column (Category feed)
	if ( 'sale_price' == $column ) {
	    $value = '';
	}

	// force empty sale price column (ListingLoader feed)
	if ( 'sale-price' == $column ) {
	    $value = '';
	}

	return $value;
}

wpla_filter_imported_product_data

This filter allows you to customize the product details when importing listings from Amazon and creating products in WooCommerce. Available since version 0.9.6.7.

Usage

add_filter( 'wpla_filter_imported_product_data', 'my_custom_amazon_import_filter' , 10, 2 );
function my_custom_amazon_import_filter( $data, $listing ) {

	// translate and truncate publication date
	if ( isset( $data['attributes']['Publication date'] ) ) {
	    $data['attributes']['Publication date']->name  = 'Jahr';
	    $data['attributes']['Publication date']->value = date( 'Y', strtotime( $data['attributes']['Publication date']->value ) );
	}

	return $data;
}

wpla_filter_imported_condition_html

This filter allows you to customize the item condition HTML that is appended to the main product description when importing products from Amazon. Available since version 0.9.6.7.

Usage

add_filter( 'wpla_filter_imported_condition_html', 'my_custom_amazon_condition_import_filter' , 10, 2 );
function my_custom_amazon_condition_import_filter( $html, $data ) {

	// translate item conditions to german
	$html = str_replace( 'New', 'Neu', $html );
	$html = str_replace( 'Used', 'Gebraucht', $html );

	return $html;
}

wpla_filter_product_price / wpla_filter_sale_price

Allows you to filter the product price / sale price to be used for Amazon. The example code below will use the cost of good amount provided by the Cost of Good extension for WooCommerce, add $4.95 for shipping and increase it by 35%. Available since version 0.8.9.2.

Usage

add_filter( 'wpla_filter_product_price', 'my_custom_amazon_product_price' , 10, 5 );
add_filter( 'wpla_filter_sale_price',    'my_custom_amazon_product_price' , 10, 5 );
function my_custom_amazon_product_price( $price, $post_id, $product, $item, $profile ) {

	// check if cost of good is set
	$cost_of_good = get_post_meta( $post_id, '_wc_cog_cost', true );
	if ( ! $cost_of_good ) return $price;

	// apply custom math
	$price = ( $cost_of_good + 4.95 ) * 1.35;

    return $price;
}

wpla_reason_for_not_creating_wc_order

Allows you programmatically determine if WP-Lister should create an order in WooCommerce or not. The example below will skip FBA orders by returning a non-empty value, which will appear in the order history log. Return false to create the order (default). Available since version 0.9.6.8.

Usage

add_filter( 'wpla_reason_for_not_creating_wc_order', 'my_custom_amazon_order_creation_filter' , 10, 2 );
function my_custom_amazon_order_creation_filter( $reason, $wpla_order ) {
	// check if this is an FBA order
	if ( 'AFN' == $wpla_order['details']->FulfillmentChannel ) {
		// set reason to skip order
		$reason = 'FBA orders are not created in WooCommerce';
	}
	return $reason;
}

wpla_mcf_enabled_order_statuses

Allows you enable custom order statuses to be fulfilled via FBA / Multi Channel Fulfillment. Available since version 0.9.6.13.

Usage

add_filter( 'wpla_mcf_enabled_order_statuses', 'my_custom_mcf_order_status_filter' , 10, 1 );
function my_custom_mcf_order_status_filter( $allowed_order_statuses ) {
	// add custom order status (by slug)
	$allowed_order_statuses[] = 'wc-my-custom-status-slug';
	return $allowed_order_statuses;
}

wpla_available_shipping_providers

This filter allows you to customize the list of available shipping providers on the order details page.

Usage

add_filter( "wpla_available_shipping_providers", "my_custom_amazon_shipping_providers", 10, 1 );

function my_custom_amazon_shipping_providers( $shipping_providers ) {
    // define custom selection of shipping providers
    $shipping_providers = array(
        'FedEx',
        'UPS',
        'USPS',
        'Other'
    );
    return $shipping_providers;
}

wpla_after_create_order_with_nonexisting_items

Use this action hook if you need to post process WooCommerce orders that were created by WP-Lister. The example below will remove the email address from the WooCommerce order, which might be useful if you want to make sure that no other plugins (like the Follow Up Emails extension) could accidentally send emails to the alias address provided by Amazon. If you use this hook to process order line items, please keep in mind that WP-Lister might create orders for products which do not exist in WooCommerce!

Usage

add_action( 'wpla_after_create_order_with_nonexisting_items', 'my_wpla_after_create_order_action' , 10, 1 );
function my_wpla_after_create_order_action( $post_id ) {
	// remove email address from order
	update_post_meta( $post_id, '_billing_email', '' );
}

wpla_product_gallery_attachment_ids

Allows you to filter the product gallery images if you don’t want to use all available images for Amazon. Available since version 0.8.8.9.

Usage

add_filter( 'wpla_product_gallery_attachment_ids', 'my_custom_amazon_images_filter' , 10, 2 );
function my_custom_amazon_images_filter( $attachment_ids, $post_id ) {
	$attachments_for_amazon = array();
	foreach ($attachment_ids as $id) {
		// get image url
		$image_url = wp_get_attachment_image_src( $id, 'full' );
		$image_url = isset($image_url[0]) ? $image_url[0] : '';
		// check if filename contains '_amazon'
		if ( strpos( $image_url, '_amazon') ) {
			$attachments_for_amazon[] = $id;
		}
	}
	return $attachments_for_amazon;
}

wpla_product_main_image_url

Allows you to filter the main product image if you don’t want to use the default main image from WooCommerce. The example code below will use the first image with “_amazon” in its filename from the Product Gallery as the main image on Amazon. Available since version 0.8.8.11.

Usage

add_filter( 'wpla_product_main_image_url', 'my_custom_amazon_main_image_url' , 10, 2 );
function my_custom_amazon_main_image_url( $original_image_url, $post_id ) {
    $product = get_product( $post_id );
    $attachment_ids = $product->get_gallery_attachment_ids();
    foreach ($attachment_ids as $id) {
        // get image url
        $image_url = wp_get_attachment_image_src( $id, 'full' );
        $image_url = isset($image_url[0]) ? $image_url[0] : '';
        // check if filename contains '_amazon'
        if ( strpos( $image_url, '_amazon') ) {
            return $image_url;
        }
    }
    return $original_image_url;
}