WP All Import - IF/ELSE statement examples

Here are some example WP All Import [IF] statements. The criteria for an IF statment is written in XPath 1.0 syntax and can use XPath functions. Although powerful, XPath syntax can be quite complex. In many cases it might be easier to use a PHP function as shown here.

The [ELSE]<something> part is optional

Number is equal to:

[IF({price[.=0]})]Zero[ELSE]Not Zero[ENDIF]

View Modify import file before import
add_action( 'pmxi_before_xml_import', 'wp_all_import_before_xml_import', 10, 1 );
function wp_all_import_before_xml_import( $import_id ) {
$path = false;
$import = new PMXI_Import_Record();
$import->getById( $import_id );
if ( ! $import->isEmpty() ) {
switch ($import->type) {
case 'url':
View gist:2e26ff65a20c88b80c08e37783d38da2
add_action( 'pmxi_saved_post', 'post_saved', 10, 1 );
function post_saved( $id ) {
global $wpdb;
$pass = get_user_meta( $id, 'xfer_user_pass', true );
$table = $wpdb->prefix . 'users';
$wpdb->query( $wpdb->prepare(
UPDATE `" . $table . "`
SET `user_pass` = %s
View wp-increase-timeout.php
Copied from
//adjustments to wp-includes/http.php timeout values to workaround slow server responses
add_filter('http_request_args', 'bal_http_request_args', 100, 1);
function bal_http_request_args($r) //called on line 237
$r['timeout'] = 15;
return $r;
View data_feed.php
$ftp = array(
'server' => '',
'user' => 'yourusername',
'pass' => 'yourpassword'
// Connect
$ftp_connection = ftp_connect( $ftp['server'] ) or die( 'Could not connect to $ftp[$server]' );
View import-ftp-proxy.php
// Note: Anyone could access your data if they guess this URL. You should remove this file from the server
// after importing or name it to something "unguessable". For even better security use an .htaccess rule.
// If you're experiencing problems you can uncomment the following line so errors will be sent to the file.
// ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
// Enter the FTP (or HTTP) URL of your data file below. IMPORTANT: This must contain the FULL PATH of the
// file. PHP seems to always start from the root folder rather than the default folder for the given user.
$url = "";

Sometimes you might need to look up the attachment id for an imported image (or other media library file) to accommodate a third party plugin. You can use this code in the function editor.

/* Returns attachment ID for the given filename, path or URL. Argument can be a
 * URL or local file path because this will only look at the file basename. Ex - These
 * would return the same thing:
 * $id = img_id("myfile.jpg");
 * $id = img_id("");
function att_id($image_filename) {
View gist:37c552388397fa54febe1e217efc16a8
They changed how variations were displayed by default in WooCo 2.4:
function soflyy_change_threshold( $amount, $product ) {
return 100; // change this to the amount of variations you want to load
add_filter( 'woocommerce_ajax_variation_threshold', 'soflyy_change_threshold', 10, 2 );