I am trying to integrate woocommerce to AgileCRM. Reference to below question I think this plugin has the same problem, wherein the order details are updated in the CRM platform only when they come through the front-end checkout.
WooCommerce hook for order creation from admin
My issue is I am not a plugin developer and the AgileCRM team say's we might have to write our own code for that. Shame they could do it in minutes where i have to dig every function and learn the plugin development.
I have found that as part of the plugin registration it has this in
funtions.php
function AgileWC_order_status_changed()
{
global $AGILEWC_SYNC_OPTIONS;
$ordersArr = func_get_args();
$wcorder = new WC_Order($ordersArr[0]);
$order = AgileWC_getOrder($wcorder);
$orderHook = AgileCRM::$hooks['order.updated'];
if (isset($_SESSION['agileWCOrderHook'])) {
$orderHook = $_SESSION['agileWCOrderHook'];
unset($_SESSION['agileWCOrderHook']);
}
$agilecrm = new AgileCRM();
$agilecrm->customerEmail = $wcorder->billing_email;
$agilecrm->hook = $orderHook;
$agilecrm->payLoad = array("order" => $order);
$agilecrm->syncAsTags = "";
if (isset($AGILEWC_SYNC_OPTIONS['sync_product_tags'])) {
$agilecrm->syncAsTags .= "_products";
}
if (isset($AGILEWC_SYNC_OPTIONS['sync_category_tags'])) {
$agilecrm->syncAsTags .= "_categories";
}
$agilecrm->post();
}
and in the plugin registration function, there is this code
if ($AGILEWC_DOMAIN && $AGILEWC_KEY) {
if (is_array($AGILEWC_SYNC_OPTIONS)) {
if (isset($AGILEWC_SYNC_OPTIONS['track_visitors']) || isset($AGILEWC_SYNC_OPTIONS['web_rules'])) {
add_action('wp_footer', 'AgileWC_script');
}
if (isset($AGILEWC_SYNC_OPTIONS['sync_customers'])) {
add_action('woocommerce_checkout_order_processed', 'AgileWC_created_customer');
}
if (isset($AGILEWC_SYNC_OPTIONS['sync_orders'])) {
add_action('woocommerce_new_order', 'AgileWC_new_order');
add_action('woocommerce_order_status_changed', 'AgileWC_order_status_changed');
add_action('save_post_shop_order','AgileWC_order_status_changed');
add_action('woocommerce_new_customer_note', 'AgileWC_new_customer_note');
}
}
}
//Added by Me, but no action
add_action('save_post_shop_order','AgileWC_order_status_changed');
Now I have read to some post that there is no woocommerce hook that I can use to call for the orders created by Admin.
Now my question is has anyone fixed this issue and if there is any help i can get to resolve this.
Thanks,
Gautam
Related
WooCommerce subscriptions | All Products for WooCommerce Subscriptions
Does anyone know if there's a way to disable the subscribe option for a specific product variation?
i.e. product with 2x attributes: attr-1, attr-2
All of which can be bought singly or via a sub on the PDP, is there a way to disable the subscribe option for one of the attributes?
There's no succinct way using the wcsatt_product_subscription_scheme filter without a lot of JS logic.
Have reached out to WC and would love to give back if there's a more a elegant solution
add_filter('woocommerce_subscription_variation_is_purchasable', 'conditional_variation_subscription_is_purchasable', 20, 2);
function conditional_variation_subscription_is_purchasable($purchasable, $product) {
$check_attributes = [
'attribute_pa_color' => 'black',
'attribute_pa_slow-connect' => 'very-slow',
];
$matching_variation = find_matching_product_variation_id($product->get_parent_id(), $check_attributes);
if ($matching_variation == $product->get_id()) {
$purchasable = false;
}
return $purchasable;
}
function find_matching_product_variation_id($product_id, $attributes) {
return (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
new \WC_Product($product_id),
$attributes
);
}
Add the code in to the active theme functions.php file. Change the attribute names and value as required.
I'm building a website on Wordpress with Bedrock/Timber/ACF.
This site is restricted for a big major part of it.
There is 4-5 pages available for anonymous users (home, contact, login & legal/privacy policy pages).
I'm currently managed it with Timber routing with like:
Routes::map('/blog/page/:num/', function ($params) {
if (!is_user_logged_in()) {
wp_redirect(home_url().'/login');
exit();
}
$user = wp_get_current_user();
if ($user->roles[0]=="subscriber") {
$post_type="publish";
} else {
$post_type="any";
}
$query = 'order=ASC&orderby=title&paged='.$params['num'].'&post_status='.$post_type;
Routes::load('list-blog.php', $params, $query, 200);
});
However I don't know if it's the good way to do it because I can't use wordpress template hierarchy, on the admin side everytimes I want to create a new page I have to create the road...
So my solution is not flexible and hard to maintain...
Do you have some advices?
EDIT:
I almost removed all my routes by using wordpress template hierarchy. But I still have routes link to the login page because I don't want to have mysite.com/wp/login but mysite.com/login.
I would use array_key_exists instead of checking for the first var because there a situation that the subscriber role is second.
If you are using ACF you could try to add a checkbox field to your pages and query for the variable of the field.
https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
Routes::map('/blog/page/:num/', function ($params) {
if (!is_user_logged_in()) {
wp_redirect(home_url().'/login');
exit();
}
$user = wp_get_current_user();
$post_type = array_key_exists("subscriber", $user->roles) ? "publish" : "any";
$query = 'order=ASC&orderby=title&paged='.$params['num'].'&post_status='.$post_type;
Routes::load('list-blog.php', $params, $query, 200);
});
I want to be able to hide certain Wordpress Post Categories from Users dependent on their Role.
I've tried the code here:
Wordpress: Hide specific categories from User Role on the Add New page
I think its deprecated, and would really appreciate some help
add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);
function yoursite_list_terms_exclusions( $exclusions, $args ) {
global $pagenow;
if (in_array($pagenow,array('post.php','post-new.php')) && !current_user_can('see_special_cats')) {
$exclusions = " {$exclusions} AND t.slug NOT IN ('slug-one','slug-two')";
}
return $exclusions;
}
With this code nothing happens. I've tried 10+ different plugins and am really getting desperate. Thanks in advance.
add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);
function yoursite_list_terms_exclusions( $exclusions, $args ) {
global $pagenow;
if (in_array($pagenow,array('post.php','post-new.php')) &&
!current_user_can('see_special_cats')) {
$exclusions = " {$exclusions} AND t.slug NOT IN ('slug-one','slug-two')";
}
return $exclusions;
}
This code presumes that you've used a plugin like the Members plugin to create a capability called 'see_special_cats' and that you've assigned it to every role that you want to have access to the categories except of course 'Contributors'.
Since you found the plugin you may not need this, but maybe it will help someone else.
add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);
function yoursite_list_terms_exclusions( $exclusions, $args ) {
$current_user = wp_get_current_user();
// Change 'see_special_cats' to capability user must have to be able see category or categories
if ( $current_user->has_cap('see_special_cats') ) {
$capCheck = 1;
} else {
$capCheck = 0;
}
global $pagenow;
if (in_array($pagenow,array('post.php','post-new.php')) && !$capCheck) {
// Change category-slug-one and two to desired categories to hide. Additional categories may be added
// by separating with a comma. Delete ", 'category-slug-two'" to only hide one category
$exclusions = " {$exclusions} AND t.slug NOT IN ('category-slug-one', 'category-slug-two')";
}
return $exclusions;
}
This code works without using current_user_can(). Paste this code in your functions.php file. If you want to hide a category from everyone except for the Administrator role, as set up by the default hierarchical structure, change 'see_special_cats' to 'create_users'. Change category-slug-one and category-slug-two to the category slugs that you want hidden. There is no additional plugin required (I'm not sure where 'see_special_cats' comes from).
I am having an issue with duplicate content, which seems to be an out of the box issue with woocommerce. For example, our SEO company is complaining because of duplicate content because you can go to:
http://localhost/wp7/product-category/clothing/hoodies/
but you can also go to
http://localhost/wp7/product-category/hoodies/
So clothing is the parent taxonomy of hoodies. Is there a filter/code to make it so that you won't be able to navigate to just the child taxonomy link, but only allow http://www.example.com/product-category/parent/child?
Any help on this would be greatly appreciated.
Kind regards, and thanks!
I was able to work through this, with this solution. Which seems to work beautifully. Not sure of the repercussions in the woocommerce eco system, but it definitely works on the frontend.
/**
* Disallow duplicate Woocommerce taxonomy links
* |- Redirects http://www.example.com/product_cat/child to http://www.example.com/product_cat/parent/child
*/
add_action('template_redirect', function ($query) {
global $wp;
$productCatTaxonomy = 'product_cat';
if (is_tax($productCatTaxonomy)) {
$current_url = add_query_arg($wp->query_string, '', home_url($wp->request));
$current_args = parse_url($current_url);
$currentTerm = get_term_by('slug', get_query_var('term'), $productCatTaxonomy);
if (isset($current_args['query']) && !stristr($current_args['query'], '%2f')) {
$currentParentTerm = (isset($currentTerm->parent) && $currentTerm->term_id) ? get_term_by('id', $currentTerm->parent, $productCatTaxonomy) : 0;
if ($currentParentTerm) {
$childTermLink = (isset($currentTerm->term_id) && $currentTerm->term_id) ? get_term_link($currentTerm->term_id, $productCatTaxonomy) : 0;
if ($childTermLink) {
wp_redirect($childTermLink);
die();
}
}
}
}
return $query;
});
I have being looking in internet how can I disable the option of edit profile in Wordpress for a user and I did't find a good way. The problem is that I want that the 95% of users can edit their profiles (address, telephone,...) but there is another 5% that I don't want them to have access to the profile section.
The best solution for me is to select manually the users that I want to disable but I also thought about create a role or a group of users to manage it.
There is no plugin for this and the only thing I have found is the following code but it is not working.
add_action('admin_init', 'user_profile_fields_disable');
function user_profile_fields_disable() {
global $pagenow;
// apply only to user profile or user edit pages
if ($pagenow!=='profile.php' && $pagenow!=='user-edit.php') {
return;
}
// do not change anything for the administrator
if (current_user_can('administrator')) {
return;
}
if (current_user_can('custom_role') {
add_action( 'admin_footer', 'user_profile_fields_disable_js' );
}
}
/**
* Disables selected fields in WP Admin user profile (profile.php, user-edit.php)
*/
function user_profile_fields_disable_js() {
?>
<script>
jQuery(document).ready( function($) {
var fields_to_disable = ['email', 'role'];
for(i=0; i<fields_to_disable.length; i++) {
if ( $('#'+ fields_to_disable[i]).length ) {
$('#'+ fields_to_disable[i]).attr("disabled", "disabled");
}
}
});
</script>
<?php
}
You have to substitude the "custom_role" with the name of the role I have assign to the user.
Is that code obsolete or bad? Any idea of how to solve it?
Thanks.