0

When importing and creating/updating products in WooCommerce the fields used in and by ATUM Stock Management doesn't get updated.

On the stockmanagementlabs forum one user posted a suggestion to be added to functions.php:

add_action('pmxi_saved_post', 'post_saved', 10, 1);

function post_saved($id) {
    // get custom field
    $purchase_price = get_post_meta($id, '_atum_purchase_price', true);

    // Insert the field into the database
    if(isset($purchase_price)){
        $wpdb->update( 
            "{$wpdb->prefix}atum_product_data", 
            array( 
                'column1' => 'purchase_price', 
                'column2' => $purchase_price 
            ), 
            array(
                'product_id' => $id
            ),
            array( 
                '%s', 
                '%d' 
            ),
            array( '%d' )
        );
    }

    // Clean up unneeded custom field (OPTIONAL)
    delete_post_meta( $id, '_atum_purchase_price' )
}

This was later somewhat updated and revised by a developer of ATUM:

add_action('pmxi_saved_post', 'after_wpai_post_saved');

function after_wpai_post_saved($id) {
    // get custom field
    $purchase_price = get_post_meta($id, '_atum_purchase_price', true);

    // Insert the field into the database
    if( $purchase_price !== FALSE ){
        $wpdb->update( 
            "{$wpdb->prefix}atum_product_data", 
            array( 
                'purchase_price' => $purchase_price,               
            ), 
            array(
                'product_id' => $id
            ),
            array('%f'),
            array('%d')
        );
    }

    // Clean up unneeded custom field (OPTIONAL)
    delete_post_meta( $id, '_atum_purchase_price' )
}

This code however renders the white screen of death.

What I basically want to be able to do is import supplier ($supplier), supplier's SKU ($supplier_sku) and purchase price ($purchase_price) to ATUM while using WPAI to create/import products.

0

perhaps a new answer on an old post. But what you getting is an error on this part:

$wpdb->update() this is because the variable $wpdb is nog defined.
To get this working, you should place global $wpdb; at the beginning of your function. like:

function after_wpai_post_saved($id) {
    global $wpdb;
    // get custom field
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.