Forum Replies Created

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • Ian Rarity
    Participant

    Hi @BOLA

    I’m currently adding monthly membership to my WC Vendors website and encountered the same issue as you. I have noticed a few posts from you trying to figure this one out, so I thought I would add how I got around this to help you out 🙂

    Firstly, I took the code that @FERVOUS kindly provided, and then added a couple of extra functions within her if statements.

    Basically what happens here is this: When a user cancels their membership they are downgraded to customer role (as per FERVOUS’ code), and then an extra function is fired that automatically marks all their products to draft (so not to show them in the shop). Now, a membership might be cancelled due to a declined payment and not because the vendor actually cancelled their membership. If the vendor signs up again with a new (or corrected) payment method, we don’t want the vendor to have to go through and manually publish all their products again. Therefor we add the same function again within the function that sets their role to vendor, but doing the opposite (set all products to published again).

    *I am not a very good coder*, I simply managed to get this function to work through trial and error – but it does seem to work exactly how I need it to on my development site.

    NOTE: I have removed the option for vendors to save draft products. If you allow them to save draft products, this could cause an issue as they would also get auto published too.

    Perhaps @FERVOUS and @BEN could have a quick look over to see if you spot anything that could pose any potential issues?

    // PAID MEMBERSHIPS PRO — UPGRADE TO VENDOR, DOWNGRADE TO SUBSCRIBER – AND UPDATE PRODUCT STATUS

    /*
    Members signing up for membership level #1 get “Vendor” role.
    Members cancelling are given the customer role.
    Admin users are ignored.
    Vendor products status is updated to draft if membership cancelled or published if active.
    */
    function my_pmpro_after_change_membership_level($level_id, $user_id)
    {
    //get user object
    $wp_user_object = new WP_User($user_id);

    //ignore admins
    if(in_array(“administrator”, $wp_user_object->roles))
    return;

    if($level_id == 1)
    {

    function update_product_status( $user_id, $new_role, $old_roles ) {

    global $wpdb;

    $update = array(
    ‘post_status’ => ‘publish’
    );

    $where = array(
    ‘post_type’ => ‘product’,
    ‘post_status’ => ‘draft’,
    ‘post_author’ => $user_id
    );

    $updated = $wpdb->update( $wpdb->posts, $update, $where );
    }

    add_action( ‘set_user_role’, ‘update_product_status’, 10, 3 );

    //New member of level #1. Give them Vendor role.
    $wp_user_object->set_role(‘vendor’);
    }

    elseif($level_id == 0)
    {

    function update_product_status( $user_id, $new_role, $old_roles ) {

    global $wpdb;

    $update = array(
    ‘post_status’ => ‘draft’
    );

    $where = array(
    ‘post_type’ => ‘product’,
    ‘post_status’ => ‘publish’,
    ‘post_author’ => $user_id
    );

    $updated = $wpdb->update( $wpdb->posts, $update, $where );
    }

    add_action( ‘set_user_role’, ‘update_product_status’, 10, 3 );

    //Cancelling. Give them Customer role.
    $wp_user_object->set_role(‘customer’);
    }
    }
    add_action(‘pmpro_after_change_membership_level’, ‘my_pmpro_after_change_membership_level’, 10, 2);

    in reply to: Display Shipping Charge To Customers #36139
    Ian Rarity
    Participant

    @ben absolutely, just left you one now 🙂

    https://wordpress.org/support/topic/the-best-multi-vendor-plugin-hands-down

    in reply to: Display Shipping Charge To Customers #35828
    Ian Rarity
    Participant

    Hi Jamie ( @digitalchild )

    Thank you so much, you are an absolute star!

    Do you guys have a donations button? I’d love to buy you both a few beers 😀

    Cheers

    in reply to: Display Shipping Charge To Customers #35750
    Ian Rarity
    Participant

    Hi Jamie ( @digitalchild ),

    Thanks for your guidance… Makes total sense now you pointed that out!

    After your advice I’ve defined the variables for $shipping_flat_rates within the function.

    It all looks OK (from a novice view), and the appropriate variables should be getting populated, but it’s still not picking it up.

    Could you possibly quickly scan over it to see if anything obvious stands out? (without taking up too much of your time!)

    In the interest of keeping this thread tidy I’ve added the code to pastbin – http://pastebin.com/HatxLYzP

    Thanks guys, you and Ben are both so helpful 🙂

    in reply to: Display Shipping Charge To Customers #35727
    Ian Rarity
    Participant

    Hi Jamie,

    Thanks for the tip! 🙂

    in reply to: Display Shipping Charge To Customers #35621
    Ian Rarity
    Participant

    Hi Ben,

    I’ve put this code together, but my knowledge is basic at best!

    I’ve added the below code to my theme functions page. The action hook is working as the function seems to be firing. The thing is it give the “no shipping found…..”.

    I’m guessing it doesn’t know a product/user to return the shipping for… How can I tell it ‘for each line item’ ?

    // seller shipping in basket for each line item
    add_action( ‘pre_user_query’, ‘DisplaySellerShipping’ );

    global $woocommerce;

    function DisplaySellerShipping() {
    if ( is_cart() ) {

    if ( ! empty( $shipping_flat_rates[ ‘national’ ] ) || ! empty( $shipping_flat_rates[ ‘international’ ] ) ) : ?>

    <table>

    <?php if ( $shipping_flat_rates[ ‘national_disable’ ] !== ‘yes’ ): ?>
    <?php if ( strlen( $shipping_flat_rates[ ‘national’ ] ) >= 0 || strlen( $shipping_flat_rates[ ‘national_free’ ] ) >= 0 ) : ?>
    <?php $free = ( array_key_exists( ‘national_free’, $shipping_flat_rates ) && $shipping_flat_rates[ ‘national_free’ ] == ‘yes’ ) ? true : false; ?>
    <?php $price = $free ? __( ‘Free’, ‘wcvendors-pro’ ) : wc_price( $shipping_flat_rates[ ‘national’ ] . $product->get_price_suffix() ); ?>
    <tr>
    <td width=”60%”><?php _e( ‘Within ‘, ‘wcvendors-pro’ ); ?><?php echo $countries[ strtoupper( $store_country ) ]; ?></td>
    <td width=”40%”><?php echo $price; ?></td>
    </tr>
    <?php endif; ?>
    <?php endif; ?>

    <?php if ( $shipping_flat_rates[ ‘international_disable’ ] !== ‘yes’ ): ?>
    <?php if ( strlen( $shipping_flat_rates[ ‘international’ ] ) > 0 || strlen( $shipping_flat_rates[ ‘international_free’ ] ) > 0 ) : ?>
    <?php $free = ( array_key_exists( ‘international_free’, $shipping_flat_rates ) && $shipping_flat_rates[ ‘international_free’ ] == ‘yes’ ) ? true : false; ?>
    <?php $price = $free ? __( ‘Free’, ‘wcvendors-pro’ ) : wc_price( $shipping_flat_rates[ ‘international’ ] . $product->get_price_suffix() ); ?>
    <tr>
    <td width=”60%”><?php _e( ‘Outside ‘, ‘wcvendors-pro’ ); ?> <?php echo $countries[ strtoupper( $store_country ) ]; ?></td>
    <td width=”40%”><?php echo $price; ?></td>
    </tr>
    <?php endif; ?>
    <?php endif; ?>
    </table>

    <?php else: ?>

    <h5><?php _e( ‘No shipping rates are available for this product.’, ‘wcvendors-pro’ ); ?></h5>

    <?php endif;
    }
    }

    in reply to: Display Shipping Charge To Customers #35617
    Ian Rarity
    Participant

    Hi Ben,

    Sorry for the delay, been extremely busy… That’s awesome about the new Tesla, they run on 18650s??? We also sell a Telsa e-cig lol.

    Thanks for sending over the info, that’s perfect. I’m turning my attention to it now, so I’ll post the code when done.

    Cheers!

    in reply to: Woocommerce Theme Support #32585
    Ian Rarity
    Participant

    Hi Ben,

    Excellent 🙂

    Just to update you lol…. Since my last post I’ve discovered that my pro dashoard was only actually working correctly if user role ‘vendor’ (all other roles including ‘pending_vendor’ stripped the 2 closing tags).

    Point to note: As I use classipress, for the above to work correctly the user needs to have role of ‘contributor’ at all times, therefore I now allow users to have multiple roles. I force all users to auto set ‘vendor’ as role now, so I don’t need my original php if statement anymore as all users are also ‘vendors’ – therefore displaying correctly.

    Obviously this isn’t perfect as it bypasses vendor application/approval etc… – but for now it works.

    (FREE Dashboard worked correctly at all time for some bizarre reason).

    Cheers

    in reply to: Woocommerce Theme Support #32524
    Ian Rarity
    Participant

    Hi Ben,

    I’ve actually just noticed that the stripping of two </div> tags is dependant on user role. If the user role is either ‘administrator’ or ‘pending_vendor’ the two tags are stripped. (so actually did look fine for standard users).

    I’ve used a temporary fix of amending my php if statements (above) to including user role as a condition.

    Have you heard this before? Any ideas why that would be?

    Cheers!

    in reply to: Woocommerce Theme Support #32521
    Ian Rarity
    Participant

    Hi Ben,

    Once again, thanks for replying to my message so quick yesterday – and for pointing me in the right direction!!

    I just wanted to post here what fixed things for me, as I’ve been a little stranded with this. I have no doubt this was a theme issue but like most other theme sellers, they’re just sh*t with support and help…

    Woocommerce documentation for integrating using hooks is less than comprehensive, and I focused all my time trying to get the theme function hooks to work and my opening / closing tags to match (this is all they mention). I see now that this was completely pointless (in my case) and this alone was never going to work (with my theme).

    After Ben mentioned templating woocommerce, it immediately dawned on me to try using a combination of my placed tags in the function page hooks AND also continuing the matching of the tags in each applicable woocommerce template. This finally fixed my main layout and compatibility issue.

    I then discovered another issue when I noticed that everything was working perfectly except the PRO dashboard (FREE dashboard worked fine). After a little digging I noticed that something was stripping out two closing divs (</div></div>) from after <div class=”wcvendors-pro-dashboard-wrapper”></div>.

    Although I still haven’t figured out what’s causing that yet, a quick fix was to put a simple php echo inside page.php which stated to print the two missing divs if on PRO dashboard. All is working correctly now, and when I find out what was stripping my closing divs I’ll post it here.

    I hope this post at least helps a few people 🙂

    Thanks Ben – your plugin is dynamite!!!

    in reply to: Woocommerce Theme Support #32445
    Ian Rarity
    Participant

    Hi Ben,

    Thanks for your reply! It was definitely worth the ask lol, I always try and do everything myself and also know why things are happening, but this has just got me totally bugged out!!! I know it will be a simple fix, I’ve just not discovered it yet…

    Thanks for your advice, I’ll start again with archive-product.php and see how I get on.

    Much appreciated 🙂

    Ian

Viewing 11 posts - 1 through 11 (of 11 total)