wordpress help??

Discussion in 'General Chat' started by razer1, Jun 26, 2015.

  1. razer1

    razer1
    Active Member

    Joined:
    Jan 5, 2011
    Messages:
    923
    Products Owned:
    0
    Products Wanted:
    0
    Trophy Points:
    46
    Location:
    Leicester
    Ratings:
    +162
    I know there are some very knowledgeable brains in here so hopefully someone who knows more with wordpress than I do is about... .

    Basically, I have created a woocommerce site. All running okay but now tinkering more with it.

    Products are simple prods & also variables too. I have in place currently a plugin that uses the regular price as a RRP and the sales price as price.

    Now, ive found a solution for the simple products to add a custom field into the admin & to show it on the user front end. - This works for simple products as I want it to.

    Now im trying to do the same for variables and I can't get it to work as intended.

    So far, I have used these guides to get this far.
    This one for the simply products
    WooCommerce Custom Product Fields | Gerhard Potgieter

    This was adapted for variable rrp pricing.
    WooCommerce Custom Fields for Variations | Remi Corson

    I have the variables to show in the admin & save but cant get it to show on the front end.

    Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.

    Link to functions file for the site.


    Any help would be great if anyone can. Im tearing my hair out and going square eyed looking now!

    TIA
     
  2. razer1

    razer1
    Active Member

    Joined:
    Jan 5, 2011
    Messages:
    923
    Products Owned:
    0
    Products Wanted:
    0
    Trophy Points:
    46
    Location:
    Leicester
    Ratings:
    +162
    Anyone as tearing my hair out trying to sort this now...
     
  3. imightbewrong

    imightbewrong
    Distinguished Member

    Joined:
    Dec 6, 2005
    Messages:
    54,349
    Products Owned:
    0
    Products Wanted:
    0
    Trophy Points:
    167
    Location:
    Romford-ish
    Ratings:
    +35,523
    What is your actual problem? An error, or not knowing what to do?

    Your file doesn't seem to be there btw:

    upload_2015-6-29_22-9-47.png
     
  4. razer1

    razer1
    Active Member

    Joined:
    Jan 5, 2011
    Messages:
    923
    Products Owned:
    0
    Products Wanted:
    0
    Trophy Points:
    46
    Location:
    Leicester
    Ratings:
    +162
    I cant get the rrp field to show for variable products.

    The code in the first link works as intended for simple products so used the other guide to add a custom field for variables.

    Ive got the field to show and save in the admin for variable products but not to show.

    It says to use the get_meta to get the field to show but...

    No matter what combo i use, cant get it to show. From what i can figure out, the field needs to show in the price.php template.

    Rather than trying to upload files, ive just pasted the variables rrp code i used in the functions.php file.

    I just need to work out what im missing for getting the price to show...



    <!--<!-- varibles -->

    <?php

    //Display Fields
    add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
    //JS to add fields for new variations
    add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
    //Save variation fields
    add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 );

    /**
    * Create new fields for variations
    *
    */
    function variable_fields( $loop, $variation_data, $variation ) {
    ?>
    <tr>
    <td>
    <?php
    // Text Field
    woocommerce_wp_text_input(
    array(
    'id' => 'rrp_variation['.$loop.']',
    'label' => __( 'RRP Price', 'woocommerce' ),
    'placeholder' => 'RRP: £',
    'desc_tip' => 'true',
    'description' => __( 'RRP Price for product', 'woocommerce' ),
    'value' => get_post_meta( $variation->ID, 'rrp_variation', true )
    )
    );
    ?>
    </td>
    </tr>

    <?php
    }

    /**
    * Create new fields for new variations
    *
    */
    function variable_fields_js() {
    ?>
    <tr>
    <td>
    <?php
    // Text Field
    woocommerce_wp_text_input(
    array(
    'id' => 'rrp_variation[ + loop + ]',
    'label' => __( 'RRP Price', 'woocommerce' ),
    'placeholder' => 'RRP:£',
    'desc_tip' => 'true',
    'description' => __( 'RRP Price for Product', 'woocommerce' ),
    'value' => ''
    )
    );
    ?>
    </td>
    </tr>

    <?php
    }

    /**
    * Save new fields for variations
    *
    */
    function save_variable_fields( $post_id ) {
    if (isset( $_POST['variable_sku'] ) ) :

    $variable_sku = $_POST['variable_sku'];
    $variable_post_id = $_POST['variable_post_id'];

    // Text Field
    $rrp_variation = $_POST['rrp_variation'];
    for ( $i = 0; $i < sizeof( $variable_sku ); $i++ ) :
    $variation_id = (int) $variable_post_id[$i];
    if ( isset( $_rrp_variation[$i] ) ) {
    update_post_meta( $variation_id, 'rrp_variation', stripslashes( $rrp_variation[$i] ) );
    }
    endfor;


    endif;
    }
    ?>
     

Share This Page

Loading...