Forum Replies Created

Viewing 15 replies - 1 through 15 (of 23 total)
  • Thread Starter Demorden

    (@demorden)

    UPDATE: I found it’s easy to solve this via phpmyadmin, it’s just that apparently the plugin (either this or multilingualpress, I still have to figure that) writes a “.” less than necessary in the db. ??

    EDIT-UPDATE-2 SO I DON’T “TRIPLE-POST”:

    Not even phpmyadmin is needed, it’s enough to check in
    Network Admin -> Sites

    site by site, I could correct the URL.

    I’m not sure whether this is a bug with MultilingualPress, with this specific plugin, or just with my site, but still it could (and I’m pretty sure it would) scare most of the people who could face the same problem. So please look into it.

    On a different note, I’m discovering that while all the content seems correctly imported (wow!), I have to re-set all the theme options, and the menus.

    I’m not sure if that is by design or not, I’m just pointing things out.
    BTW, I’m testing it on a stagin site, and I’ll leave more feedback after some more tests.

    That said, great plugin overall! ??

    Thread Starter Demorden

    (@demorden)

    Oh, great tip, thanks.
    I’ll do it ASAP. ??

    Have a nice day/evening/whatever-it-is-in-your-time-zone. ??

    Thread Starter Demorden

    (@demorden)

    Hello again Stanislav, since I’m starting to save (and share) my snippets on Github, I took the liberty to include the one I used for your plugin. ??

    It’s as simple as you could imagine, but it works, and could be useful to someone else as well.

    I saved it as a plugin and made it compatible with Github Updater, so that anyone could easily use it if needed.

    https://github.com/Demorden/prerendering-rules-for-wp-instant-articles

    I would love if you could take 5 minutes to review it; I am mainly concerned with giving the correct credits and licenses.

    Thanks for all ??

    Thread Starter Demorden

    (@demorden)

    It works like a charm! ^_^
    Simply awesome.

    Now I’ll add some code to decide per-post whether to ADD rules or to OVERRIDE them.
    Then I will really feel ready to use it in production.

    Thanks, I’m changing my rating to 5 stars. ??
    Have a nice day! ??

    Thread Starter Demorden

    (@demorden)

    Thanks for the quick answer.

    If I understand correctly, you are saying that with the upcoming version, if I use a filter like the one we discussed, it will override the prerendering rules, rather than being an addition?

    (Just to make it crystal-clear: what I’d like to achieve is that if I set “post1” and “post5” as prerendered pages, all other rules are ignored. For pages with no such settings, the default rules are applied.)

    Very cool! ??

    I understand that a built-in GUI to override the rules is not a priority.
    If the filter will work as intended, it would be more than enough for now.

    I’m leaving 4 stars, waiting for the new version.
    I’m sure I’ll have to change my rating to 5 stars, for this reason – and other improvements as well. ??

    Keep on with the good work! ^_^

    PS: I’ll set this as solved as soon as the filter will be able to completely override the rules, but I’m set for now. ??

    Thread Starter Demorden

    (@demorden)

    Ok, I’ve seen it works with CPT.
    It had to, after all. ??

    Now to the serious things. ??
    Just so that you know, I’ve tested my idea as exposed above, and I rewrote your snippet into this:

    add_filter('wpinstant_prerendered_urls', function($urls) {
        $values = get_field('articolo_prerender');
            if($values) {
                foreach($values as $value) {
                    $permalink = get_permalink( $value );
                    if($permalink) {
                        $urls[] = $permalink;
                    }
                }
            }
    return $urls;
    });

    (reference: https://www.advancedcustomfields.com/resources/code-examples/#working-with%20array%20values )

    On my posts I set up a field with ACF – a post-object outputting the selected posts IDs.
    Well, it works just fine.

    BUT this setup just ADDS posts to the prerendering list, whilst my goal was to OVERRIDE the default settings completely.

    Any help on that?
    Thanks a lot. ??

    Thread Starter Demorden

    (@demorden)

    Ok thanks for all, marking as solved. ??

    Thread Starter Demorden

    (@demorden)

    Ok everything is much clearer now, thanks.

    I hate to bother you with silly questions, but please understand, this plugin is quite specific in its purpose, and I never tried anything similar. ??

    If you want to accept a humble suggestion, you could go much deeper in details in the documentation, because your work is not intuitive for everyone (and that’s a shame, since it could help everyone – a lot). It’s not for me at least. ??

    And also, it’s not something I feel like playing randomly. ??

    Now just two more questions and I’ll leave you to your work. ??

    Plugin filters are for pages that are not represented by a post type

    So can I block plugins just by post type? How?

    For instance if you want to disable a plugin on the admin you would enter your admin url

    So something like “https://domain.com/category/” would affect “category” and all sub-urls? Or should I rather use “https://domain.com/category/*”? Does it accept regular expressions?

    Thanks a lot!
    This will help me with a complex site. ??

    Thread Starter Demorden

    (@demorden)

    Hello Michael,

    I followed your tips and they were useful (except there’s no need for absint(), as the woocommerce code includes validation and only allows integers).

    As anticipated, I also changed something to make the whole idea better. ??

    (Truth be told, I tried something more complex in the beginning, and I ALMOST made it work, but I had some issue related to the saving function. I guess this is something I’d better ask on Woocommerce Support forums.)

    I rewrote a line so that now the achievement is awarded on order_status_completed, which made much more sense indeed.
    And it worked with no issue.

    Then I thought “what if for any reason the seller wants to award the badge as soon as the payment is received? Let’s add a checkbox for that!”

    And I tried the code below, which must have some issue related to the final if – elseif part, where it’s supposed to decide whether to award immediately or after order is completed, based on said checkbox.

    I say so because the field appears and is saved correctly, but the achievement is awarded no matter the value.

    It’s most likely a stupid error, but sincerely I got to the point I can’t see it. Could you help please? ??

    // WOOCOMMERCE ADD CUSTOM PRODUCT FIELD: RELATED BADGE
    
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    function woo_add_custom_general_fields() {
    
    global $woocommerce, $post;
    echo '<div class="options_group">';
    
    woocommerce_wp_text_input(
    array(
    'id' => '_achievement_field',
    'label' => __( 'Achievement Granted', 'woocommerce' ),
    'placeholder' => '',
    'description' => __( 'Enter the Badge ID here.', 'woocommerce' ),
    'type' => 'number',
    'custom_attributes' => array(
    'step' => 'any',
    'min' => '0'
    )
    )
    );
    
    woocommerce_wp_checkbox(
    array(
    'id' => '_paid',
    'wrapper_class' => 'show_if_simple',
    'label' => __('Awarded on payment?', 'woocommerce' ),
    'description' => __( 'Award after payment but before order complete', 'woocommerce' )
    )
    ); 
    
    echo '</div>';
    } 
    
    function woo_add_custom_general_fields_save( $post_id ){
    
    $achievement_field = $_POST['_achievement_field'];
    if( !empty( $achievement_field ) )
    update_post_meta( $post_id, '_achievement_field', esc_attr( $achievement_field ) );
    
    $paid_checkbox = isset( $_POST['_paid'] ) ? 'yes' : 'no';
    update_post_meta( $post_id, '_paid', $paid_checkbox ); 
    
    }
    
    //
    // BUY PRODUCT = GAIN RELATED ACHIEVEMENT
    //
    
    if ( $paid_checkbox = 'yes' ) {
    add_action('woocommerce_payment_complete', 'custom_process_order_paid', 10, 1);
    function custom_process_order_paid($order_id) {
        $order = new WC_Order( $order_id );
        $myuser_id = (int)$order->user_id;
        $items = $order->get_items();
        foreach ($items as $item) {
        	$product_id = $item['product_id'];
    	badgeos_award_achievement_to_user( get_post_meta( $product_id, '_achievement_field', true ), $myuser_id );
        		}
        	    return $order_id;
        	    }
    	} elseif ( $paid_checkbox = 'no' ) {
    
    add_action('woocommerce_order_status_completed', 'custom_process_order_completed', 10, 1);
    function custom_process_order_completed($order_id) {
        $order = new WC_Order( $order_id );
        $myuser_id = (int)$order->user_id;
        $items = $order->get_items();
        foreach ($items as $item) {
        	$product_id = $item['product_id'];
    	badgeos_award_achievement_to_user( get_post_meta( $product_id, '_achievement_field', true ), $myuser_id );
    		}
    	    return $order_id;
        	    }
    	}

    Thanks in advance!

    PS:
    You know, this small coding adventure is being frustrating in some moments, but overall funny. ??

    Thread Starter Demorden

    (@demorden)

    Hi and thanks again.

    Your tips apart (which totally make sense and I’ve already implemented), I’ve found a couple of minor functional imperfections.
    Not in my code, but in the idea behind it…

    And I told myself: “since you’re doing it anyway, you might as well do it well”. ??

    So I’m changing a couple of details; I might ask for another feedback or two, later, if you don’t mind.

    In any case, I’m glad that in the worst scenario, anyone who will be interested in this kind of feature now has at least a starting point to work on. ??

    Thread Starter Demorden

    (@demorden)

    Hi Michael, and thanks for your precious feedback. ??

    While I was waiting for more comments, I ended up with this code, which is already ready as an addon.

    The first part generates a custom field in the “General” Product data Tab, which must be populated with an integer (the achievement ID).

    The second part is just an evolution of we previously discussed, using the inserted metadata to automatically select the desired achievement.

    Tested and works. ^_^
    If you think there are no obvious issues with it (or optimizations) I’m planning to release it as a plugin on the WordPress repository.

    Aaaand… here’s the code:

    // WOOCOMMERCE ADD CUSTOM PRODUCT FIELD: RELATED BADGE
    
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    function woo_add_custom_general_fields() {
    
    global $woocommerce, $post;
    echo '<div class="options_group">';
    
    woocommerce_wp_text_input(
    array(
    'id' => '_achievement_field',
    'label' => __( 'Achievement Granted', 'woocommerce' ),
    'placeholder' => '',
    'description' => __( 'Enter the Badge ID here.', 'woocommerce' ),
    'type' => 'number',
    'custom_attributes' => array(
    'step' => 'any',
    'min' => '0'
    )
    )
    );
    
    echo '</div>';
    } 
    
    function woo_add_custom_general_fields_save( $post_id ){
    
    $achievement_field = $_POST['_achievement_field'];
    if( !empty( $achievement_field ) )
    update_post_meta( $post_id, '_achievement_field', esc_attr( $achievement_field ) );
    }
    
    // BUY PRODUCT = GAIN RELATED ACHIEVEMENT
    
    add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
    function custom_process_order($order_id) {
        $order = new WC_Order( $order_id );
        $myuser_id = (int)$order->user_id;
        $user_info = get_userdata($myuser_id);
        $items = $order->get_items();
        foreach ($items as $item) {
    	$product_id = $item['product_id'];
    	$badge_id = get_post_meta( $product_id, '_achievement_field', true );
    	badgeos_award_achievement_to_user( $badge_id, $myuser_id );
        }
        return $order_id;
    }
    Thread Starter Demorden

    (@demorden)

    Hey, I’m happy to know that my code is not bad, it looked so simple that in my mind it had to be. ??

    So thanks for the validation.
    (So proud right now. ^_^ )

    I’ll try to move in the direction you suggested, let me just check if I got your tip right:

    1. store the associated badge id in product meta;
    2. call for the meta in my code so that the the association will happen automatically.

    Would you mind if I post here the resulting code when I’ll be done?
    If you don’t mind giving further feedback of course.

    So, in case someone else will be interested, they’ll be able to find a final, clean and (somewhat) automated solution.

    I am persuaded that such code, with some refining of course, could make a good addon for those who want to gamify the shopping experience.

    Thanks for now. ??

    PS – EDIT:
    One thing that concerns me is the achievement gaining procedure: isn’t it a little… raw? Is there a better way to do it? (without thousands of lines of code I mean ?? )

    Thread Starter Demorden

    (@demorden)

    Sorry for the double post, but I’ve an update.

    I’ve been able to change the shortcode to “ombox” (although I can’t still insert it automatically via UI -trying to get this result- it’s enough to correct the output shortcode… ok for now).

    I humbly suggest you to do the same, or implement a similar solution, to avoid future possible issues. ??

    Maybe the best would be a “compatibility mode” that, if activated, would trigger modified shortcodes. The main plus of this solution would be this: those who have a lot of “old” shortcodes in their pages, with no issues, could simply ignore this special setting and keep using their shortcodes. No hassle.

    Those who have issues would have an easy way to solve.

    The question now is… are you going to do this move?
    And if not, could you suggest me a plugin-updates-proof way to make my change persistent?

    THANKS! ^_^

    +1, because their apparent server issue (or whatever is happening) broke something in the plugin. Namely, I seem unable to reactivate the premium functions after the latest update. I thought that maybe I just inserted a wrong password (unlikely, since it’s saved, but I tried before ranting), but I can’t even go on the site to check.

    All in all, I guess the plugin is just trying to connect to prettylinkpro.com and can’t… just like me.

    NOT cool!

    If the devs are reading… I don’t know if you decided to discontinue the plugin.
    (If connection issues lasted so long, and such a question goes unanswered for a week, that’s the first thing that comes to mind)

    It’s annoying if you did, but it’s still legal, we won’t sue you, so don’t be shy… ??
    Just tell us if we should start considering alternatives.

    (and find a solution to my inability to use the features I paid for, please)

    Thread Starter Demorden

    (@demorden)

    In fact, during the last hour, I could find another feature that would be awesome.
    Filtering by user custom fields.

    I explain better (or try to):

    I am building a site for my company, and I plan to let users add a lot of (optional) informations to let us know them better.

    Today, I had an idea: show some content only to those that indicate that they’re our customers, and not only visitors (we sell physical goods, but plan to do some content marketing too, so we’ll have visitors who are not customers).

    I have limited knowledge of user data in the db (never needed to seriously mess with that), but I guess you understood the suggestion and have an idea of how to possibly implement it.

    To give you a reference, think about Gravity Forms, and its ability to make post.
    There is an input that lets you set custom fields, either existing or new.

    Not sure I was clear, English is not my language and -on top of that- I need to write in a hurry.

Viewing 15 replies - 1 through 15 (of 23 total)