November 3, 201511 yr Hi All, Having a bit a trouble with this code added to themes functions.php file. Trying to add a new Custom Field Wordpress/Woocommerce, in Admin Panel Product>General>Sku and also show it on Single Product Page front end just under the SKU. The Field being added is "Brand". Everything I have so far is working as expected. Field "Brand" has been created and it will save the inputed text. Also The Heading Brand is showing on Frontend. The Problem is retrieving the inputed text. Can not figure out correct call function and keep getting a Fatal error at that line. I am including the code below I am using and Highlighting the line I am having trouble with. // Display Fields add_action( 'woocommerce_product_options_sku', 'wc_brand_product_field' ); function wc_brand_product_field() { woocommerce_wp_text_input( array( 'id' => 'brand_field', 'class' => 'wc_input_sku short', 'label' => __( 'Brand', 'woocommerce' ) ) ); } // Save Fields using WooCommerce Action Hook add_action( 'save_post', 'wc_brand_save_product' ); function wc_brand_save_product( $product_id ) { if ( isset( $_POST['brand_field'] ) ) { if ($_POST['brand_field'] ) if ( $_POST['brand_field'] ) update_post_meta( $product_id, 'brand_field', $_POST['brand_field'] ); } } add_action( 'woocommerce_single_product_summary', 'wc_brand_show', 5 ); function wc_brand_show() { global $product; Do not show this on variable products if ( $product->product_type <> 'variable' ) { $brand = get_post_meta( $product->id, 'brand_field', true ); echo '<div class="woocommerce_brand">'; _e( 'Brand: ', 'woocommerce' ); echo '<span class="woocommerce_brand_field_sku-wrapper">' . woocommerce_product_meta_sku_wrapper( $brand ) . '</span>'; echo '</div>'; } } I have highlighted the line above I am having trouble with. I know I am not pointing to correct ID class. I just can't figure out. If I point it to _price class it works without error but forces numeric layout. Any help on this would be much appreciated. Thanks in advance. Joe
November 3, 201511 yr Author Consider this request closed. Finally figured it out when I simplified it. Here is the code that fixed it. add_action( 'woocommerce_single_product_summary', 'wc_brand_show', 5 ); function wc_brand_show() { $brand = get_post_meta( $product->id, 'brand_field', true ); _e( 'Brand: ', 'woocommerce' ); echo get_post_meta( get_the_ID(), 'brand_field', true ); } Thanks to anyone who was taking a crack at it
Create an account or sign in to comment