Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Fixed this.

    In my upload I had half filled out customer/logged out prices that had a regular price, but no selling prices. For some reason this was interfering with the shopkeeper price.

    When I removed any extra half filled prices, except the shopkeeper price, which was fully filled out with both a regular and a selling price. It fixed the problem, defaulted regular users to the default word-press price. And displayed the shopkeeper price correctly with VAT.

    Any word on version 3.0?

    Or a work-around to add variable prices by csv?

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    RESOLVED: I fixed the problem.

    For it to work, I not only had to move ‘header-centered.php’, but all of it’s sub files, starting with header.php, header-centered.php and so fourth. Can anyone explain why this is, or the theory behind this? I kind of get it, but not quite.

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Did a little digging, found this:

    https://wordpress.stackexchange.com/questions/26822/how-to-override-javascript-files-in-child-theme/26824#26824

    Correct me if I’m wrong, but it seems to point out that child themes only overwrite common ‘core’ wordpress template files by default. like header.php footer.php, so because ‘header-centered.php’ is not a common/core name, it’s not recognised.

    Therefore, in order to rewrite header-centered.php, I need to find where header-centered.php is enqueued, dequeue it, and requeue my own version?

    • This reply was modified 8 years, 4 months ago by PleasantlyOdd.
    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    This is what I ended up using for now, although surely not ideal, it worked.

    // the following code will do nothing if the user is a shopkeeper, but remove the stock text if the user is not a shopkeeper, or if the user is not logged in.
          global $current_user;
    
          if( !empty($current_user->roles) ){ //if current user is not empty get the current user roles
            foreach ($current_user->roles as $key => $value) {
                if( $value == 'shopkeeper'){
                    //if the user is a shopkeeper, do nothing
                } else {
                    //if the user is not a shopkeeper, remove the stock text
                    add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
                    function wcs_custom_get_availability( $availability, $_product ) {
                        $availability['availability'] = __('', 'woocommerce');
                        return $availability;
                    }
                }
            }
          } else if( empty($current_user->roles) ){       //else if the current user is empty, remove the stock text
              add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
              function wcs_custom_get_availability( $availability, $_product ) {
                  $availability['availability'] = __('', 'woocommerce');
                  return $availability;
              }
          }
    //end
    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Update: The following code will remove the text for the stock count, if the user is a shopkeeper. Which works, now I just need to reverse it so that it applies to everyone whose *not* a shopkeeper.

    Updates are still welcome for that or if you know a more efficient way.

          $user = wp_get_current_user();
          if ( in_array( 'shopkeeper', (array) $user->roles ) ) {
            add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
            function wcs_custom_get_availability( $availability, $_product ) {
                $availability['availability'] = __('', 'woocommerce');
                return $availability;
            }
          }
    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    I resolved this issue with some different code for anyone interested.

    I used:

    <div class="product_after_shop_loop_switcher<?php if( !current_user_can( 'shopkeeper' )){ echo ' product_after_shop_loop_switcherOFF'; } ?>">

    With the above, the product animations are on as default. But if the current user !is not a ‘shopkeeper’, the animations will be disabled.

    _____

    The above assumes your override css sets the animations to none !important;

    I would also like to do this. Would appreciate any help.

    So far I know how to add a new option title and where its meant to hook in, but I’m a bit unsure what to put in the conditions field to hide the content if they are a shopkeeper.

    add_filter( 'if_menu_conditions', 'wpb_new_menu_conditions' );
    
    function wpb_new_menu_conditions( $conditions ) {
      $conditions[] = array(
        'name'    =>  'shopkeeper', // name of the condition
        'condition' =>  function($item) {          // callback - must return TRUE or FALSE
          return is_post_type_archive();
        }
      );
    
      return $conditions;
    }
    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    SOLVED!

    ____

    It’s running perfectly now, I took the code apart and rewrote it, I think, although I’m not sure, the problem was caused by:

    $twitter = get_user_meta( $user_id, ‘twitter’, true );
    $url = $user->user_url;

    Not being filled in correctly.

    _____

    My new code is pasted below for anyone that needs, this code will add the custom field ‘storeID’ to your word press admin backed, as well as your woocommece user account information, it then checks to see if the user has filled in the field with the our super secret keyword, which in this case is ‘potato’ and – if it is correct, it grants them the higher user permission of ‘shopkeeper’:, not too shabby for a php newbie if I do say so myself.

    // this code adds 'StoreID' to the wordpress Admin so you can see it in the backend
    add_filter('user_contactmethods', 'modify_contact_methods');
    
    function modify_contact_methods($profile_fields) {
    
      // Add new fields
      $profile_fields['StoreID'] = 'Store ID (retailers only)';
    
      return $profile_fields;
    }
    //end
    
    add_action( 'woocommerce_edit_account_form', 'my_woocommerce_edit_account_form' );
    add_action( 'woocommerce_save_account_details', 'my_woocommerce_save_account_details' );
    
    function my_woocommerce_edit_account_form() {
    
      $user_id = get_current_user_id();
      $user = get_userdata( $user_id );
    
      if ( !$user )
        return;
    
      $StoreID = get_user_meta( $user_id, 'StoreID', true );
    
      ?>
    
      <fieldset>
        <legend>Activation (Retail Only):</legend>
        <p>If you're a stockist of the Real Effect, enter your invoicing code here to activate online invoicing.</p>
        <p class="form-row form-row-thirds">
          <label for="StoreID">Activation:</label>
          <input type="password" name="StoreID" value="<?php echo esc_attr( $StoreID ); ?>" class="input-password" />
        </p>
      </fieldset>
    
      <?php
    
    }
    
    //if the code is right, grants them shopkeeper permission
    add_action( 'profile_update', 'my_profile_update' );
    
    function my_profile_update( $user_info ){
        $user_info = get_userdata( $user_info );
        if ( $user_info->StoreID === 'potato' ){
          $user_info->set_role( 'shopkeeper' );
        }
    }
    
    //controls the saving of woo commerce data
    function my_woocommerce_save_account_details( $user_id ) {
    
      update_user_meta( $user_id, 'StoreID', htmlentities( $_POST[ 'StoreID' ] ) );
    
      $user = wp_update_user( array( 'ID' => $user_id, 'StoreID' => esc_url( $_POST[ 'password' ] ) ) );
    
    }
    
    ?>
    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    <?php
    function my_profile_update( $user_info ){
        $user_info = get_userdata( $user_info );
        if ( $user_info->StoreID === 'activatestore5879' ){
          $user_info->set_role( 'shopkeeper' );
        }
      } ?>
    
    <?php function my_woocommerce_save_account_details( $user_id ) {
    
      update_user_meta( $user_id, 'StoreID', htmlentities( $_POST[ 'StoreID' ] ) );
    
    }

    The above is the part of the code that I’m currently using to apply the permission change.

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Thanks James, will do!

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    I have solved this problem, for anyone looking I used:

    <?php if( current_user_can('editor') || current_user_can('administrator') ) { ?>

    With a closing } tag.

    The full code was:

    <?php if( current_user_can('editor') || current_user_can('administrator') ) {  ?>
        <?php if ($main_header_shopping_bag == true) : ?>
        <li class="shopping-bag-button" class="right-off-canvas-toggle">
            <a href="javascript:void(0)">
                <?php if ( (isset($mr_tailor_theme_options['main_header_shopping_bag_icon']['url'])) && ($mr_tailor_theme_options['main_header_shopping_bag_icon']['url'] != "") ) : ?>
                <img src="<?php echo esc_url($mr_tailor_theme_options['main_header_shopping_bag_icon']['url']); ?>">
                <?php else : ?>
                <i class="getbowtied-icon-shop"></i>
                <?php endif; ?>
                <span class="shopping_bag_items_number"><?php echo $woocommerce->cart->cart_contents_count; ?></span>
            </a>
        </li>
        <?php endif; ?>
    <?php } ?>
    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Thank you so much for your help, both of you! I came back to share my solution with the community. What I ended up doing was a combination of both of your inputs.

    ____

    I made it so that when the user updates his last name with the keyword ‘uniquename’, it changes their user permissions. Here’s the code I used, I left it as editor for example reasons:

    <?php
        add_action( 'profile_update', 'my_profile_update', 10, 2 );
    
        function my_profile_update( $user_info ){
          $user_info = get_userdata( $user_info );
          if ( $user_info->last_name === 'uniquename' ){
            $user_info->set_role( 'editor' );
          }
        }
    ?>

    ____

    I’m still very new to PHP hooks/actions though, whats the importance of the 10, 2? would it not work if they were different numbers? from what I understand they’re position values, but what makes the profile update position 10 or why does my function need to be position 2?

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Thanks for your replies! All very good points, looks like I might be able to try a unique identifier with that second link, i’ll try tomorrow and let you know how it goes.

Viewing 14 replies - 1 through 14 (of 14 total)