PW Bulk Edit Plugin

Bulk edit fields in the Split Pay Plugin using the PW Bulk Edit plugin.

The Split Pay Plugin is compatible with the PW Bulk Edit plugin. We do not yet have a full integration including user interface for making bulk edits, so making bulk edits requires the use of the code example below for now.

One of our wonderful customers requested more information about how to bulk edit fields in the Split Pay Plugin for products and variable products. They were using the PW Bulk Edit plugin found on WordPress.org.

The PW Bulk Edit plugin would allow you to modify the following fields:

The database field storing the option for Percentage or Fixed Amount:

_bsd_spscwt_product_type

This database field storing the fixed amount transfer value:

_bsd_spscwt_product_amount

This database field storing the percentage transfer value:

_stripe_connect_split_pay_transfer_percentage

For reference, you can copy/paste the example code below and put it into a php file in your Plugins folder in order to bulk edit those fields in the PW Bulk Edit plugin:

<?php
/**
 * Plugin Name: Custom PW Bulk Edit Columns
 * Description: PW Bulk Editor Custom Columns for Split Pay for Stripe Connect.
 * Author:      Pimwick, LLC / Michael McHugh @ DigitalFusion
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

//Custom PW Bulk Edit Columns for Transfer/ Split Payment Amount
function pw_bulk_edit_custom_columns( $columns ) {

     $columns[] = array(
        'name' => 'Percentage',
        'type' => 'text',
        'table' => 'meta',
        'field' => '_stripe_connect_split_pay_transfer_percentage',
        'visibility' => 'both',
        'readonly' => false,
        'sortable' => 'false'
    );

    $columns[] = array(
        'name' => 'Fixed Amount',
        'type' => 'text',
        'table' => 'meta',
        'field' => '_bsd_spscwt_product_amount',
        'visibility' => 'both',
        'readonly' => false,
        'sortable' => 'false'
    );

    return $columns;
}
add_filter( 'pwbe_product_columns', 'pw_bulk_edit_custom_columns' );

//Custom PW Bulk Edit SELECT Columns
function pw_bulk_edit_custom_meta_fields() {
    global $pw_bulk_edit_custom_meta_fields;

    //
    // Define the custom meta fields below.
    //
    $pw_bulk_edit_custom_meta_fields = array(
        // The meta key value
        '_bsd_spscwt_product_type' => array(
            // The name
            'name' => 'Variable Product-Specific Transfer',
            // The options available in the dropdown menu.
            'options' => array(
                'percentage' => 'Percentage',
                'amount' => 'Fixed Amount',
            ),
        ),
    );
}
add_action( 'woocommerce_init', 'pw_bulk_edit_custom_meta_fields' );

function custom_pwbe_select_options( $select_options ) {
    foreach ( $GLOBALS['pw_bulk_edit_custom_meta_fields'] as $field_name => $field ) {

        foreach ( $field['options'] as $option_key => $option_name ) {
            $select_options[ $field_name ][ $option_key ]['name'] = $option_name;
            $select_options[ $field_name ][ $option_key ]['visibility'] = 'both';

            $select_options[ 'attribute_' . $field_name ][ $option_key ]['name'] = $option_name;
            $select_options[ 'attribute_' . $field_name ][ $option_key ]['visibility'] = 'both';
        }
    }

    return $select_options;
}
add_filter( 'pwbe_select_options', 'custom_pwbe_select_options' );

function custom_pwbe_product_columns( $columns ) {
    foreach ( $GLOBALS['pw_bulk_edit_custom_meta_fields'] as $field_name => $field ) {
        $columns[] = array(
            'name' => $field['name'],
            'type' => 'select',
            'table' => 'meta',
            'field' => $field_name,
            'readonly' => 'false',
            'visibility' => 'both',
            'sortable' => 'true',
            'views' => array( 'all', 'standard' )
        );
    }

    return $columns;
}
add_filter( 'pwbe_product_columns', 'custom_pwbe_product_columns' );

function pw_bulk_edit_filter_types( $filter_types ) {
    foreach ( $GLOBALS['pw_bulk_edit_custom_meta_fields'] as $field_name => $field ) {
        $filter_types[ $field_name ] = array( 'name' => $field['name'], 'type' => 'attributes' );
    }

    return $filter_types;
}
add_filter( 'pwbe_filter_types', 'pw_bulk_edit_filter_types' );

function pw_bulk_edit_common_joins( $common_joins ) {
    global $wpdb;

    foreach ( $GLOBALS['pw_bulk_edit_custom_meta_fields'] as $field_name => $field ) {
        $common_joins .= "
            LEFT JOIN
                {$wpdb->postmeta} AS meta_$field_name ON (meta_$field_name.post_id = post.ID AND meta_$field_name.meta_key = '$field_name')
        ";
    }

    return $common_joins;
}
add_filter( 'pwbe_common_joins', 'pw_bulk_edit_common_joins' );

function pw_bulk_edit_search_row_sql( $row_sql, $search_class, $field_name, $filter_type, $field_value, $field_value2 ) {
    global $pwbe_sql_builder;

    if ( isset( $GLOBALS['pw_bulk_edit_custom_meta_fields'][ $field_name ] ) ) {
        $row_sql = $pwbe_sql_builder->multiselect_search( "meta_$field_name.meta_value", $filter_type, $field_value );
    }

    return $row_sql;
}
add_filter( 'pwbe_search_row_sql', 'pw_bulk_edit_search_row_sql', 10, 6 );

function pw_bulk_edit_after_filter_select_templates() {

    foreach ( $GLOBALS['pw_bulk_edit_custom_meta_fields'] as $field_name => $field ) {
        ?>
        <span class="pwbe-multiselect pwbe-filter-<?php esc_attr_e( $field_name ); ?>-container pwbe-filter-<?php esc_attr_e( $field_name ); ?>-template" style="display: none;">
            <select name="filter_select[]" class="pwbe-filter-field pwbe-filter-select pwbe-filter-value" multiple="multiple" ></select>
        </span>
        <?php
    }
}
add_action( 'pwbe_after_filter_select_templates', 'pw_bulk_edit_after_filter_select_templates' );

Feel free to reference the PW Bulk Edit plugin documentation for further assistance.

Last updated