Forum Replies Created

Viewing 15 replies - 16 through 30 (of 74 total)
  • I was referring to the action hook add_action('the_post', 'my_function') but the underscore was stripped. This is executed at the start each of the posts in the loop. This is where you could run your code. ??

    This action hook only fires at the start of each loop (so just once). So if $box_count probably wouldn’t be higher than 1 at any given time. For instance the post runs on every iteration of the loop, so this one might do the trick.

    This should be placed in your functions.php file. You can check the WooCommerce hook reference to check if there is a more appropriate action you could use if your checkout does not involve payments.

    https://docs.woothemes.com/wc-apidocs/hook-docs.html

    Plugin Author tormorten

    (@tormorten)

    Thanks for letting me know. This was a huge error on my behalf and I’m really sorry. Both these errors should be fixed with the latest update (1.0.1) which was just released.

    The woocommerce_payment_complete action is run once a payment has been completed. Have you tested that?

    This would pull the entire lifetime account spend. So if the threshold is set to 10000, an order of 100 would not trigger an account type change if the current account was at 9000. But an order or 1000 would.

    Ok, so I have not tested it, but it could do the trick.

    The first function finds the amount spent on each order from a specific email address. Usage: woocommerce_get_amount_spent('[email protected]')

    The second function changes the user role if the user has spent a certain amount of cash. Usage: customer_change_role(1, 400, 'iuseallmymoneyhere') The first parameter is the user ID, the second is the minimum amount to achieve the role and the third is the name of the role.

    You could hook this in to the checkout process of WooCommerce so that immediately after they complete an order they get the new role.

    add_filter('woocommerce_payment_complete', function($order_id) {
    
    	$order = new WC_Order($order);
    	$user_id = $order->user_id;
    
    	if($user_id) {
    		customer_change_role($user_id, 600, 'bigspender');
    	}
    
    });
    /**
     * Gets the amount an email has spent
     * @param  string $email Users email
     * @return float
     */
    function woocommerce_get_amount_spent($email) {
    
    	$orders = get_posts( array(
    	    'meta_key'    		=> '_billing_email',
    	    'meta_value'  		=> $email,
    	    'post_type'   		=> 'shop_order',
    	    'posts_per_page'	=>-1
    	) );
    
    	$spent = 0;
    	foreach($orders as $shop_order) {
    		$order = new WC_Order($shop_order->ID);
    		$spent += $order->get_total();
    	}
    
    	return $spent;
    
    }
    
    /**
     * Change a customers role when they spend big money
     * @param  integer 	$user_id   	The ID of the user. Current user when none supplied
     * @param  integer 	$threshold 	How much money do we need?
     * @param  string 	$role 		Which role to give
     * @return void
     */
    function customer_change_role($user_id = null, $threshold = 600, $role = 'bigspender') {
    
    	// when the user_id was not supplied we'll try and figure it out
    	if($user_id === null) {
    		$user_id = get_current_user_id();
    	}
    
    	// this probably means the user is not logged in
    	if( !$user_id ) {
    		return;
    	}
    
    	// get the user object
    	$user = get_user_by('id', $user_id);
    
    	// nope, something went wrong
    	if(!$user) {
    		return;
    	}
    
    	// the user is a big spender, lets give him a role
    	if(woocommerce_get_amount_spent($user->data->user_email) >= $threshold) {
    		$user->add_role($role);
    	}
    	// this mofo ain't using money. take it back!
    	else {
    		$user->remove_role($role);
    	}
    
    }
    Forum: Hacks
    In reply to: Plugin updates

    WordPress has a Plugin Update API which checks every plugin a couple of times every day to see if there are any new updates to it.

    When your plugin is hosted with www.remarpro.com this does not require any extra code on your end, as it is already in the WordPress core.

    With wp-updates or other update methods you either install another plugin which checks it for you, or you add some class and set some properties, which in turn hooks into the Plugin Update API so updates are run through the same procedures as WP.org plugins.

    Either way there is little control on how you notify your users on new updates as they both probably use the same check cycle. wp-updates probably has a method to force update checks or change the cycle to occur more often.

    Hi,

    This can be achived using a action hook.

    At the start of the main loop (while(have_posts()) and so on) the action called loop_start is fired. So you could do this.

    add_action('loop_start', 'my_awesome_loop_start');
    
    function my_awesome_loop_start() {
    	dynamic_sidebar(‘WidgetArea1’);
    }

    This would apply to every single loop start, so it would also work on archives.

    Does that answer your question?

    Hi,

    Here’s a link explaining why it fails on stuff with -webkit, and -moz in front of them.

    In short, vendor prefixes is not defined in the CSS specification and thus would cause an error. They are allowed, and follow the correct specifications, but as long as they’re not the specs they will fail.

    Hi,

    I use the Aqua Resizer when working with images in WordPress.

    This has the option to upscale your images so they always fit in a set format.

    Hi,

    How about this one: Simple Staff List?

    Tor

    Forum: Fixing WordPress
    In reply to: HACK

    You are missing one of the key components of the WordPress’ administration list tables. Try uploading a fresh copy of wp-admin/ via your ftp.

    So, do you see posts or do you not see posts?

    In your original post your said you got no result, but now you see results?

    Anyways, you have no pagination in your code.

    The WP Query need the paged parameter du decide which page you are on. Even then you will get no new results (as -1 already lists all posts).

    From the WordPress Codex:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
      'posts_per_page' => 3,
      'paged' => $paged
    );
    
    query_posts($args);
    ?>

    You need to tell WordPress which page you are on, and how many you want per page (not infinity as there is no infinity*2)

    Using get_queried_object()->ID could also work if you are on a page where the post object has been set.

Viewing 15 replies - 16 through 30 (of 74 total)