Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Ultimate › Custom Field
- This topic has 3 replies, 2 voices, and was last updated 4 years, 9 months ago by r_guayaquil.
- AuthorPosts
- February 28, 2020 at 4:51 am #109142r_guayaquilParticipant
Hi,
Long ago you guys helped with the following code to show a dollar sign in a custom field set as text because the vendor que type text or number.
You also helped with a code to show the same custom field in the shop page, but the dollar sign doesnt show. Can you please help me to also show the dollar sign in the shop page? Please see images attched.
The code to show the custom field in shop page is:
add_action(‘woocommerce_after_shop_loop_item_title’, function() {
global $WCFM, $WCFMmp, $product;if( !$product ) return;
$product_id = $product->get_id();
if( $product_id ) {
$wcfm_product_custom_fields = get_option( ‘wcfm_product_custom_fields’, array() );
if( $wcfm_product_custom_fields && is_array( $wcfm_product_custom_fields ) && !empty( $wcfm_product_custom_fields ) ) {
foreach( $wcfm_product_custom_fields as $wpcf_index => $wcfm_product_custom_field ) {
if( !isset( $wcfm_product_custom_field[‘enable’] ) ) continue;$block_name = !empty( $wcfm_product_custom_field[‘block_name’] ) ? $wcfm_product_custom_field[‘block_name’] : ”;
$wcfm_product_custom_block_fields = $wcfm_product_custom_field[‘wcfm_product_custom_block_fields’];$display_data = ”;
foreach( $wcfm_product_custom_block_fields as $wcfm_product_custom_block_field ) {
if( !$wcfm_product_custom_block_field[‘name’] ) continue;
$field_name = $wcfm_product_custom_block_field[‘name’];
if( !in_array( $field_name, array( ‘costo_de_envio’ ) ) ) continue;$field_value = get_post_meta( $product_id, $field_name, true );
if( $field_value ) {
$display_data .= “<label class=’wcfm_custom_field_display_label’ style=’display:inline-block;’>” . wcfm_removeslashes( __( $wcfm_product_custom_block_field[‘label’], ‘wc-frontend-manager’) ) . “: </label>”;
$display_data .= “<span class=’wcfm_custom_field_display_value’>” . $field_value . “</span><br />”;
}
}if( $display_data ) {
echo ‘<div class=”wcfm_custom_field_display wcfm_custom_field_display_’.sanitize_title($block_name).'”>’;
echo $display_data;
echo ‘</div><div class=”wcfm-clearfix”></div>’;
}
}
}
}
}, 45 );And the code to show the dollar sign automatically is:
add_filter( ‘wcfm_custom_field_value’, function( $field_value, $field_name ) {
if( $field_value && is_numeric( $field_value ) && ( $field_name == ‘costo_de_envio’ ) ) {
$field_value = get_woocommerce_currency_symbol() . $field_value;
}
return $field_value;
}, 50, 2 );Thanks a lot for the help!
Attachments:
You must be logged in to view attached files. - March 2, 2020 at 10:14 pm #109595r_guayaquilParticipant
Hi,
Any help? 🙂
- March 4, 2020 at 1:54 pm #109873WCFM ForumMember
Hi,
Please add this line –
$field_value = apply_filters( 'wcfm_custom_field_value', $field_value, $field_name );
after this line – $field_value = get_post_meta( $product_id, $field_name, true );
Thank You
- March 5, 2020 at 9:28 pm #110135r_guayaquilParticipant
Thank you so much! 🙂
- AuthorPosts
- You must be logged in to reply to this topic.