• Resolved newtocodeing

    (@newtocodeing)


    Okay I read most of these support forums and you said if someone would produce some code to help integrate your plugin with WooCommerce you might consider making it work?.

    Okay here we go. The issue with WooCommerce not working with this plugin, as I understand it, has to do with the endpoints in the my account section I think. Basically woocommerce handles the my account section differently than one would expect if they had only used wordpress and never worked with WooCommerce before. What I was able to do is create a custom endpoint and name it pgp. So now when you go to the my account page you see all of the normal stuff and now there is the additional link named PGP. That link should point to “woocommerce/myaccount/pgp.php” i think based off my code below.

    So now I think all that is left is to write 1 file named pgp.php and that file will need to be placed in woocommerce/myaccount. But I do not know PHP very well at all and I have no idea how this plugin receives information. Basically I have a good idea what needs to be done but I do not have the PHP skills to finish.

    Here is the code that will allow you to define a custom endpoint and add a link into the My Account menu.

    I might be a tiny bit wrong on a few small issues but I think this is the solution and I suspect that once someone is able to write this pgp.php file all of this could be bundled up in a fully functional plugin. It seems like if you create pgp.php and have it populate the fields that the plugin requires then the problem is solved. I promise I am learning PHP as quickly as possible but it just seems like this could be easily fixed in very little time with this information. Maybe there is more to this than I understand and it is REALLY difficult? Please help.

    Place this code in functions.php

    function my_custom_endpoints() {
    add_rewrite_endpoint( ‘pgp’, EP_ROOT | EP_PAGES );
    }

    add_action( ‘init’, ‘my_custom_endpoints’ );

    function my_custom_query_vars( $vars ) {
    $vars[] = ‘pgp’;

    return $vars;
    }

    add_filter( ‘query_vars’, ‘my_custom_query_vars’, 0 );

    function my_custom_flush_rewrite_rules() {
    flush_rewrite_rules();
    }

    add_action( ‘after_switch_theme’, ‘my_custom_flush_rewrite_rules’ );
    function my_custom_my_account_menu_items( $items ) {
    $items = array(
    ‘dashboard’ => __( ‘Dashboard’, ‘woocommerce’ ),
    ‘orders’ => __( ‘Orders’, ‘woocommerce’ ),
    //’downloads’ => __( ‘Downloads’, ‘woocommerce’ ),
    //’edit-address’ => __( ‘Addresses’, ‘woocommerce’ ),
    //’payment-methods’ => __( ‘Payment Methods’, ‘woocommerce’ ),
    ‘edit-account’ => __( ‘Edit Account’, ‘woocommerce’ ),
    ‘pgp’ => ‘PGP’,
    ‘customer-logout’ => __( ‘Logout’, ‘woocommerce’ ),
    );

    return $items;
    }
    add_filter( ‘woocommerce_account_menu_items’, ‘my_custom_my_account_menu_items’ );
    function my_custom_endpoint_content() {
    include ‘woocommerce/myaccount/pgp.php’;
    }

    add_action( ‘woocommerce_account_pgp_endpoint’, ‘my_custom_endpoint_content’ );

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Meitar

    (@meitar)

    Thank you so much for going through this effort. I hope it was educational (and fun!) to do and learn. Thanks also for letting me know you are new to coding. If you’re interested in learning more, please allow me to offer some suggestions.

    First, as discussed before, it is somewhat difficult to communicate about such precise things as coding on a support forum like this:

    Any developer who wants to do this can coordinate with me about the issue on GitHub.

    Code contributions could instead be submitted via the project’s issue tracker, which provides a smoother way to discuss changes. Please have a look at the WP PGP Encrypted Emails repository on GitHub to see what I mean.

    Second, the functions.php file is not a plugin file. This means the plugin, by convention and politeness, has no right to place code in that file. That file is for a Theme’s developer or, if the Theme is a child theme, the administrator of the site itself. In contrast, code in this plugin should apply to all themes, regardless of which is active on a particular site. It must therefore not use the theme’s functions.php file to place its code.

    Third, while the code you’ve provided might work, it’s extremely invasive. You’re registering a unique rewrite endpoint, but provide no fallback for when such an endpoint is not available, such as when WordPress “pretty permalink” are unavailable for some reason or another. It also appears to make modifications to WooCommerce’s own menu system, which seems like it would not work for anyone who wanted those menu items to remain.

    I’ve coded an alternative implementation for you to have a look at and try out, if you wish. If you do want to try it out, download and install the latest development version of the plugin. I encourage you to comment on the commit on GitHub if you’d like to discuss the implementation choices, and why they are lighter-weight, and hopefully easier to maintain in the future. ??

    Thanks again for poking me enough to look further into this. If this integration works for you (and the others who have expressed interest in WooCommerce integration), then I’ll roll it up into the next release version of the plugin.

    Plugin Author Meitar

    (@meitar)

    Just a note to say that I have just released version 0.7 of this plugin, featuring full WooCommerce integration. Enjoy, and do let me know if there are any issues. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce Integration – I have read your posts and I have some code to offer’ is closed to new replies.