Custom Field

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 3 reply threads
  • Author
    Posts
    • #109142
      r_guayaquil
      Participant

      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.
    • #109595
      r_guayaquil
      Participant

      Hi,

      Any help? 🙂

    • #109873
      WCFM Forum
      Member

      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 );

      https://ibb.co/xX8JHG8

      Thank You

    • #110135
      r_guayaquil
      Participant

      Thank you so much! 🙂

Viewing 3 reply threads
  • You must be logged in to reply to this topic.