I have a user role called "Wholesale" already created.
I have used to following snippet to create a custom field on every product that allows me to input some value in it:
function snippet_add_custom_pricing() {
$args = array(
'label' => __( 'Wholesale', 'woocommerce' ),
'placeholder' => __( 'Price for wholesale', 'woocommerce' ),
'id' => 'snippet_wholesale',
'desc_tip' => true,
'description' => __( 'Price for Wholesale.', 'woocommerce' ),
);
woocommerce_wp_text_input( $args );
}
add_action( 'woocommerce_product_options_pricing', 'snippet_add_custom_pricing' );
function snippet_save_custom_meta( $post_id ) {
// Value of the price
$pricing = isset( $_POST[ 'snippet_wholesale' ] ) ? sanitize_text_field( $_POST[ 'snippet_wholesale' ] ) : '';
// Name of the product
$product = wc_get_product( $post_id );
// Saves Metafield
$product->update_meta_data( 'snippet_wholesale', $pricing );
$product->save();
}
add_action( 'woocommerce_process_product_meta', 'snippet_save_custom_meta' );
This is working, now I just want to show the values introduced here to all Wholesale users, so that when they login they get the price that is inserted on this field and not the regular price. Is this possible?
I've tried this thread but it did not work for me.