Forum Replies Created

Viewing 15 replies - 1 through 15 (of 118 total)
  • Thread Starter kosmicbird

    (@kosmicbird)

    Nevermind, I resolved it now. Couldn’t use translation with this because of how the code is implemented. For anyone else needing to do this:

    Go to /mycred/plugins/mycred-hook-woocommerce.php and copy this block of code to your child theme functions.php file:

    /**
     * Payout Rewards
     * @since 1.5
     * @version 1.1
     */
    if ( ! function_exists( 'mycred_woo_payout_rewards' ) ) :
    	function mycred_woo_payout_rewards( $order_id ) {
    
    		// Get Order
    		$order    = wc_get_order( $order_id );
    
    		// If we paid with myCRED we do not award points by default
    		if ( $order->payment_method == 'mycred' && apply_filters( 'mycred_woo_reward_mycred_payment', false, $order ) === false )
    			return;
    
    		// Get items
    		$items    = $order->get_items();
    		$types    = mycred_get_types();
    		$buyer_id = $order->user_id;
    
    		// Loop through each point type
    		foreach ( $types as $point_type => $point_type_label ) {
    
    			// Load type
    			$mycred = mycred( $point_type );
    
    			// Check for exclusions
    			if ( $mycred->exclude_user( $buyer_id ) ) continue;
    
    			// Calculate reward
    			$payout = $mycred->zero();
    			foreach ( $items as $item ) {
    
    				// Get the product ID or the variation ID
    				$product_id    = absint( $item['product_id'] );
    				$variation_id  = absint( $item['variation_id'] );
    				$reward_amount = mycred_get_woo_product_reward( $product_id, $variation_id, $point_type );
    
    				// Reward can not be empty or zero
    				if ( $reward_amount != '' && $reward_amount != 0 )
    					$payout = ( $payout + ( $mycred->number( $reward_amount ) * $item['qty'] ) );
    
    			}
    
    			// We can not payout zero points
    			if ( $payout === $mycred->zero() ) continue;
    
    			// Let others play with the reference and log entry
    			$reference = apply_filters( 'mycred_woo_reward_reference', 'reward', $order_id, $point_type );
    			$log       = apply_filters( 'mycred_woo_reward_log',       '%plural% reward for store purchase', $order_id, $point_type );
    
    			// Make sure we only get points once per order
    			if ( ! $mycred->has_entry( $reference, $order_id, $buyer_id ) ) {
    
    				// Execute
    				$mycred->add_creds(
    					$reference,
    					$buyer_id,
    					$payout,
    					$log,
    					$order_id,
    					array( 'ref_type' => 'post' ),
    					$point_type
    				);
    
    			}
    
    		}
    
    	}
    endif;

    I changed this line: $log = apply_filters( 'mycred_woo_reward_log', '%plural% reward for store purchase', $order_id, $point_type );

    to

    $log = apply_filters( 'mycred_woo_reward_log', '%plural% your purchase', $order_id, $point_type ); (just change it to what you want it to say). The implementation here is weird to me, but oh well. That’s how it is!

    Thanks for the awesome plugin.

    Thread Starter kosmicbird

    (@kosmicbird)

    I notice in WP dashboard -> credits -> hooks there are fields to change the log template – Example: %plural% for leaving a review

    But there doesn’t seem to be a place on the front-end to change where I’d assume it would be %plural% for reward store purchase. I feel like I searched every core file but found nothing. Must be missing something.

    Alright, finally figured out how to hide checkout fields on the thank you page when they are empty, and display when content has been submitted. Again, had to make a few minor changes to the code above for it to work in my situation. Here are my final working solutions for the examples I posted above:

    Custom Text Input Field

    /**
     * Add the fields to order emails and thank you page.
     **/
    add_action( "woocommerce_email_after_order_table", "my_woocommerce_number_to_call_after_order_table", 10, 1);
     
    /* add same function to run on after orders table for thank you page */
    add_action( 'woocommerce_order_details_after_order_table', "my_woocommerce_number_to_call_after_order_table", 10, 1 );
     
    function my_woocommerce_number_to_call_after_order_table( $order ) {
    
      if ($number_to_call = get_post_meta( $order->id, 'Phone Number to Call', true ) ) {
     
      echo '<p><strong>'.__('Phone Number to Call').':</strong> ' . get_post_meta( $order->id, 'Phone Number to Call', true ) . '</p>';
     
        }
    }

    Custom Text Input Field

    /**
     * Add the fields to order emails and thank you page.
     **/
    add_action( "woocommerce_email_after_order_table", "my_woocommerce_time_to_call_after_order_table", 10, 1);
     
    /* add same function to run on after orders table for thank you page */
    add_action( 'woocommerce_order_details_after_order_table', "my_woocommerce_time_to_call_after_order_table", 10, 1 );
     
    function my_woocommerce_time_to_call_after_order_table( $order ) {
    
      if ($time_to_call = get_post_meta( $order->id, 'Best Time to Call', true ) ) {
      
      echo '<p><strong>'.__('Best Time to Call').':</strong> ' . get_post_meta( $order->id, 'Best Time to Call', true ) . '</p>';
    
       } 
    }

    Custom Textarea Field

    /**
     * Add the fields to order emails and thank you page.
     **/
    add_action( "woocommerce_email_after_order_table", "my_woocommerce_script_after_order_table", 10, 1);
     
    /* add same function to run on after orders table for thank you page */
    add_action( 'woocommerce_order_details_after_order_table', "my_woocommerce_script_after_order_table", 10, 1 );
     
    function my_woocommerce_script_after_order_table( $order ) {
    
       if ($the_script = get_post_meta( $order->id, 'The Script', true ) ) {
    
       echo '<p><strong>'.__('The Script').':</strong> ' . get_post_meta( $order->id, 'The Script', true ) . '</p>';
     
       }
    }

    So to conditionally show the fields depending on whether there is content or not, you just need to add something like:

    if ($your_custom_field = get_post_meta( $order->id, 'Your Custom Field', true ) ) {

    to your function.

    Oh yea, one more thing in case someone sees this. I am trying to figure out how to conditionally show the labels/meta info depending on if the field is empty or not. I think I remember seeing this mentioned in the thread earlier but not sure if the answer was there. About to read again…

    I just want to say thanks to you guys for discussing the solution to this issue. @mgason is right, there is very little documentation on this topic that I could find (I’ve been lost until I came across this thread!!) And I agree… you would think that this is pretty basic/obvious documentation for the plugin developers to include in the tutorials section.

    I want to post something that may help someone in the future who is still having issues with this. The specific code here did not completely work for my situation, I had to change a few minor parts around to get it to work for me. However, it would have taken me forever to figure this out of you all didn’t lead me down the right path with this thread!!

    In my situation, I needed to be able to display the user-submitted order info derived from basic text input fields, as well as textarea fields. Here are a few examples of my working code (the part that adds my custom fields to the order-received (aka thank you) page:

    Custom Text Input Field

    /**
     * Add the fields to order emails and thank you page.
     **/
    add_action( "woocommerce_email_after_order_table", "my_woocommerce_number_to_call_after_order_table", 10, 1);
     
    /* add same function to run on after orders table for thank you page */
    add_action( 'woocommerce_order_details_after_order_table', "my_woocommerce_number_to_call_after_order_table", 10, 1 );
     
    function my_woocommerce_number_to_call_after_order_table( $order ) {
    echo '<p><strong>'.__('Phone Number to Call').':</strong> ' . get_post_meta( $order->id, 'Phone Number to Call', true ) . '</p>';
     
    }

    Custom Text Input Field

    /**
     * Add the fields to order emails and thank you page.
     **/
    add_action( "woocommerce_email_after_order_table", "my_woocommerce_time_to_call_after_order_table", 10, 1);
     
    /* add same function to run on after orders table for thank you page */
    add_action( 'woocommerce_order_details_after_order_table', "my_woocommerce_time_to_call_after_order_table", 10, 1 );
     
    function my_woocommerce_time_to_call_after_order_table( $order ) {
    echo '<p><strong>'.__('Best Time to Call').':</strong> ' . get_post_meta( $order->id, 'Best Time to Call', true ) . '</p>';
     
    }

    Custom Textarea Field

    /**
     * Add the fields to order emails and thank you page.
     **/
    add_action( "woocommerce_email_after_order_table", "my_woocommerce_script_after_order_table", 10, 1);
     
    /* add same function to run on after orders table for thank you page */
    add_action( 'woocommerce_order_details_after_order_table', "my_woocommerce_script_after_order_table", 10, 1 );
     
    function my_woocommerce_script_after_order_table( $order ) {
       echo '<p><strong>'.__('The Script').':</strong> ' . get_post_meta( $order->id, 'The Script', true ) . '</p>';
     
    }

    So here I had three different custom checkout fields I needed to display on the order-received (thank you) page. The code shown above places your custom fields directly after the order table, as you can assume. Those needing to place the custom fields in other areas can look here to find the appropriate hook: https://docs.woocommerce.com/wc-apidocs/hook-docs.html

    For instance, if you wanted to add your custom fields underneath the “Custom details” section, you would substitute woocommerce_order_details_after_customer_details in place of woocommerce_order_details_after_order_table

    Here is a trick I used to make this a whole lot easier. If you’re like me, you might have already used the available woo documentation to display field values on the order edit page found here: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

    Here is the code template to display your custom checkout field values on the order edit page:

    /**
     * Display field value on the order edit page
     */
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
    
    function my_custom_checkout_field_display_admin_order_meta($order){
        echo '<p><strong>'.__('My Field').':</strong> ' . get_post_meta( $order->id, 'My Field', true ) . '</p>';
    }

    Since I had many fields I needed to display, I simply copied this line

    echo '<p><strong>'.__('My Field').':</strong> ' . get_post_meta( $order->id, 'My Field', true ) . '</p>';

    from each of my custom fields that I had already set up, and pasted each line into it’s respective (order-received/thank you page) function. Think of it this way – you are displaying the checkout fields already on the order edit page with this code, you just need to use the appropriate action hooks to get it whereever you want.

    Anyway, the woocommerce people should really add documentation on this to their official site so people can find it easily. I definitely spent a big chunk of time trying to figure this out and so thankful that you guys already figured most of it out, so I just had to connect a couple of very minor situational dots. Would still be sitting here confuzzled if it weren’t for this thread. Hope my additions can help someone else in the future save some time, like you guys did for me. Thank you!

    Thread Starter kosmicbird

    (@kosmicbird)

    Problem resolved. Instead of using the code above to add my new custom field, I changed it to this:

    add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields ( $fields ) {
    
    $fields['order']['the_script'] = array (
    
    woocommerce_form_field  ( 'the_script', array(
        'type'    =>    'textarea',
        'class'   => array('extracheckoutinfo form-row-wide'),
        'label'   =>  __('What is the script?'),
        'placeholder'  =>   __('You can skin this section if you added the "script" extra to your purchase'),
        'required'    =>   true
    
    );
    
    return $fields
    
    }

    Which now allows me to target my custom field like this:

    unset ($fields['order']['the_script'] );

    @bdbrown Really? This issue affects both premium (commercial) as well as freemium users, so I think it should certainly be supported here as well as via premium user channels.

    Do you have any estimated time-frame? What has your hosting provider for the plugin told you? This is a serious situation especially for those of us who have paid for the premium version. Also do you have long term contingency plans in case something even worse happens and all of our like data is somehow lost due to hosting or any other issues? Some things to think about.

    I am also having this issue. I do not know exactly when it started but I just looked at my site and noticed the like buttons are not showing anywhere. Have not made any changes to my site in weeks. Hope you get this fixed asap.

    Thread Starter kosmicbird

    (@kosmicbird)

    Edit: I am quite confused about a few things. After monitoring the activity, the widget seems to be updating quickly, despite that the notation says it would update every 24-48 hours. However since it currently seems to be working as I need it for my specific situation, I’m going to mark this as resolved.

    Thread Starter kosmicbird

    (@kosmicbird)

    Yes, the issue was never resolved. I could not figure out what was causing the issue. But my trial period ended and I have deactivated it for now.

    Thread Starter kosmicbird

    (@kosmicbird)

    Hi! Sorry for the delayed reply, I don’t get email notifications for the forums. I am excited that you have UM plugin integration on your to do list, judging from the features listed on the description it seems exactly along the lines of what I’m looking for if it can work with UM system.

    I am building a dating site and a social networking site, and I need geolocation for both. Some specific features that would be helpful for me:

    – Display how far away User A is from User B in miles (and option to view in KM) on their UM profile
    – My users are able to submit their own “post”, the post is basically an activity that they want to do (example: User A posts that he wants to have Coffee @ Starbucks @ 9am). I am using User-Submitted-Posts plugin to allow them to do this on the front end) within their post I want them to be able to type in the location of the activity they are posting (with address autocomplete functionality). So ideally there would be a way (maybe with shortcode) to insert the location autocomplete box (not sure how to call it properly) on the page they are making their post with, and then it would all link together. Don’t think this would have much to do with UM integration (maybe more-so with User Submitted Posts plugin) but just an idea of how I would need to use geolocation features.
    – I want other users to be able to go and search all of the site’s global posts by proximity to the current user’s current location (option to view activities posted within 5 miles, 10 miles, 15 miles, 500 miles, any distance etc of the user’s current location)
    – Also would be excellent for User B to click on User A’s activity post and see how far away that activity’s location is from the user B’s current location (option to see driving time for User B to get to activity location of User A is a big plus too)

    This is not an exhaustive list, but the ones I can think of right now. I am still planning out the exact geolocation features I need, but this is to just give you an idea. Really, it sounds like I could use every feature that you have listed in the functionality, especially complex location search filtering.

    Thread Starter kosmicbird

    (@kosmicbird)

    Ohh! I didn’t even realize that there were settings on the front-end for this. Thanks for the help, awesome plugin!

    • This reply was modified 7 years, 10 months ago by kosmicbird.
    Thread Starter kosmicbird

    (@kosmicbird)

    Edit: I’ve been doing some testing and exploring, I think I’ve figured part of the problem out. It looks like it’s only logging page views from visitors who are not logged in, and not logging page views from users who are logged into their account. ??

    That would make sense why I perceived that the view count updates were inconsistent – it’s not that they had any refresh lag, it’s just that the views from me while logged in were not counting – and when I saw the count update it was because a visitor must have viewed it. I am using Ultimate Member plugin for user accounts if that makes a difference.

    • This reply was modified 7 years, 10 months ago by kosmicbird.
    • This reply was modified 7 years, 10 months ago by kosmicbird.
    Thread Starter kosmicbird

    (@kosmicbird)

    Yes, I’d be happy to give some examples. If seeing the site would help, can I send you the url in email? Or what specifically can I provide you with?

    A bit of extra info that may help – I checked the WP post stats list by going to Jetpack > Site Stats > Show Me and then looking at the “Posts & Pages” summary, I don’t even see this particular post showing up on the list.

    Another user made a post within the last hour since I started this thread and the view count for his post refreshed almost immediately to 1 view (it is also showing in that post stats list as it should). However the views don’t seem to update immediately after every refresh. For instance, I tested using a different browser + IP viewing his post and it is not updating the view count, it is still stuck on the same number. **edit: about 20 minutes later now the views on his post have updated** It seems to be inconsistent with how long it takes to refresh the counts.

    No idea why the post I started this thread about just isn’t logging a count or showing up in the stats list at all (it is showing up in my WP post dashboard and everywhere else though)

    • This reply was modified 7 years, 10 months ago by kosmicbird.
    • This reply was modified 7 years, 10 months ago by kosmicbird.
Viewing 15 replies - 1 through 15 (of 118 total)