Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #449169

    I am trying to add something to my functions.php so i can add a size field below Sale Price in the General area of the Product Data.

    I would prefer to have a drop down with the sizes available and you would select one that would appear on the product page below the title.

    The closest I could find is the following, it worked but it wasn’t what I needed because it has a dollar value to it, I don’t need that. I got it to work and tried changing it to fit my needs but can’t figure it out.

    Here is what I used:

    (I got it from here: http://gerhardpotgieter.com/2013/09/17/woocommerce-custom-product-fields/)

    add_action( 'woocommerce_product_options_pricing', 'wc_rrp_product_field' );
    function wc_rrp_product_field() {
        woocommerce_wp_text_input( array( 'id' => 'rrp_price', 'class' => 'wc_input_price short', 'label' => __( 'RRP', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')' ) );
    }
    
    add_action( 'save_post', 'wc_rrp_save_product' );
    function wc_rrp_save_product( $product_id ) {
        // If this is a auto save do nothing, we only save when update button is clicked
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		return;
    	if ( isset( $_POST['rrp_price'] ) ) {
    		if ( is_numeric( $_POST['rrp_price'] ) )
    			update_post_meta( $product_id, 'rrp_price', $_POST['rrp_price'] );
    	} else delete_post_meta( $product_id, 'rrp_price' );
    }
    
    add_action( 'woocommerce_single_product_summary', 'wc_rrp_show', 5 );
    function wc_rrp_show() {
        global $product;
    	// Do not show this on variable products
    	if ( $product->product_type <> 'variable' ) {
    		$rrp = get_post_meta( $product->id, 'rrp_price', true );
    		echo '<div class="woocommerce_msrp">';
    		_e( 'RRP: ', 'woocommerce' );
    		echo '<span class="woocommerce-rrp-price">' . woocommerce_price( $rrp ) . '</span>';
    		echo '</div>';
    	}
    }
    
    // Optional: To show on archive pages
    add_action( 'woocommerce_after_shop_loop_item_title', 'wc_rrp_show' );

    ——————————————————————————————————————————————————————-
    ——————————————————————————————————————————————————————-
    I thought I had the answer with this link, it looked liked it would work but I tried it and had no luck:
    http://www.remicorson.com/mastering-woocommerce-products-custom-fields/

    My brain is mush at this point, any help is greatly appreciated.

    Thank you.

    #449865

    Hi Micheal0424!

    Thank you for using Enfold.

    You don’t need to add a code for that. You can create product variations. Refer to this link for more info: http://docs.woothemes.com/document/variable-product/

    If this is not what you’re looking for, please provide a website with the example or a screenshot. Use imgur or dropbox.

    Best regards,
    Ismael

    #451377

    Thank you.

    I saw that on the variable product.

    I saw I didn’t mention it was a simple product that I am doing this with, sorry about that.

    How can I make this work for me:

    http://www.remicorson.com/mastering-woocommerce-products-custom-fields/

    I can’t figure it out.

    Thank you.

    #451902

    Hey!.

    The code above is working. Assuming that this is what you want, you can find the RRP field under the Sales Price field in the product’s General panel. It will display in the product overview page and in the single product view as well.

    Best regards,
    Ismael

    #451907

    Yes, the code is working but I am not trying to put that code in. though.

    I am wanting to replace it with a drop down option for sizes:
    SML MED LRG

    Like this link here:
    http://www.remicorson.com/mastering-woocommerce-products-custom-fields/

    // Select
    woocommerce_wp_select(
    array(
    ‘id’ => ‘_select’,
    ‘label’ => __( ‘My Select Field’, ‘woocommerce’ ),
    ‘options’ => array(
    ‘one’ => __( ‘Option 1’, ‘woocommerce’ ),
    ‘two’ => __( ‘Option 2’, ‘woocommerce’ ),
    ‘three’ => __( ‘Option 3’, ‘woocommerce’ )
    )
    )
    );

    I just can’t get it to work for me, I know I am doing something wrong I just can’t figure it out.

    Thanks

    #452382

    Hi!

    The code is working but it doesn’t get the actual value:

    add_action( 'woocommerce_product_options_pricing', 'wc_new_option_field' );
    function wc_new_option_field() {
        woocommerce_wp_select( array(
          'id' => 'newoptions',
          'class' => 'newoptions',
          'label' => __('Testing Multiple Select', 'woocommerce'),
          'description' => __( 'Choose a value.', 'woocommerce' ),
          'options' => array(
            '1' => __( 'Option 1', 'woocommerce' ),
            '2' => __( 'Option 2', 'woocommerce' ),
            '3' => __( 'Option 3', 'woocommerce' ),
          ))
        );
    }
    
    add_action( 'save_post', 'wc_rrp_save_product' );
    function wc_rrp_save_product( $product_id ) {
        // If this is a auto save do nothing, we only save when update button is clicked
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		return;
        // Select
      if ( isset( $_POST['newoptions'] ) ) {
    		update_post_meta( $product_id, 'newoptions', $_POST['newoptions'] );
    	} else {
        delete_post_meta( $product_id, 'newoptions');
      }
    }
    
    add_action( 'woocommerce_single_product_summary', 'wc_rrp_show', 5 );
    function wc_rrp_show() {
        global $product;
    		$option = get_post_meta( $product->id, 'newoptions', true );
    		echo '<div class="woocommerce_msrp">';
    		_e( 'New Option: ', 'woocommerce' );
    		echo '<span class="woocommerce-newoption">' . $option . '</span>';
    		echo '</div>';
    
    }
    

    Please contact the woocommerce support.

    Best regards,
    Ismael

    #452393

    That works perfectly, I am now going to go back and see what I was doing wrong so I will be able to stop running this through my head over and over trying to figure it out.

    Thank you very much for your help.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘woocommerce custom product data field’ is closed to new replies.