Vivek Athalye
Forum Replies Created
-
Forum: Plugins
In reply to: [Polylang] any event that gets triggered when language is changed?When a user accesses my site for the first time, there is a PHP notice that is getting logged.
PHP Notice: Undefined index: pll_language
It is coming from
pll_current_language()
call fromwp_enqueue_scripts
action.
Any idea how to avoid it?- This reply was modified 4 years, 10 months ago by Vivek Athalye.
Forum: Plugins
In reply to: [Polylang] any event that gets triggered when language is changed?Gr8… thanks a lot for the quick reply. This solved my problem.
add_action( 'wp_enqueue_scripts', 'vna_enqueue_styles_scripts' ); function vna_enqueue_styles_scripts() { error_log('current lang: ' . pll_current_language()); error_log('prev lang: ' . $_COOKIE[ PLL_COOKIE ]); }
Just to note: I first tried the above code in
init
action, but wasn’t getting expected results. Both current lang and prev lang were blank.
But when I moved it towp_enqueue_scripts
action, it worked perfectly.I had to go out of town for couple of days, so I could not send a pull request. And now when I checked, a new version of WCMp is available with a different approach to handle Shipping Methods ??
Well… now I’ll need to understand this new approach and rewrite my code. ??Ok. NP.
I think I’ve managed it. I need some time to test and do code cleanup.
Once done will send a pull request (hopefully by tomorrow).Hi @itzmekhokan,
Yes, I figured it out on sunday and added my custom form. But that’s just one small part of it.
When we try to edit the custom shipping method instance, the method settings don’t get passed on to this form and this form remains empty. Moreover when we try to save the changes from this form, they don’t get saved. Both of these issues are caused by the code in
vendor-shipping.js
. The methodseditShippingMethod
andupdateShippingMethod
have some hardcoded logic based on if conditions such as:if (methodId == 'free_shipping') { **** } if (methodId == 'local_pickup') { **** } if (methodId == 'flat_rate') { **** }
First of all these should have been
if ... else if ... else if
and then there is no logic for custom shipping method (the lastelse
part).For the time being / testing purpose I’ve added the logic for custom shipping here but now I’m facing issue in
WCMP_Vendor_Shipping_Method::calculate_shipping
. Here also the logic is based on hardcoded method ID checking and there is no logic available for supporting custom shipping methods. So my custom shipping method’scalculate_shipping
doesn’t get called at all. ??Can you plz help me with this?
Further observations:
For the same shipping zone, I added my custom shipping method twice as site admin and twice as vendor. So there are 4 instances of my custom shipping method for the given zone and their instance IDs are as shown below.22: added by vendor
24: added by vendor
84: added by site admin
85: added by site adminNow the echoed text shows up thrice with the instance IDs: 84, 85 and 0.
@itzmekhokan On further debugging, I see my previous understanding was wrong.
I added 1 more shipping method (Local pickup). So now there are 3 shipping methods for the given zone, added by the vendor. But still the text appears twice only. So its not dependent on the number of shipping methods. (But it still appears for all shipping methods.)
So to understand why its showing up twice, I echoed
$this->id . ':' . $this->instance_id . ' - does this show up? ';
. The instance IDs are 84 and 0. I can see that 84 is the instance ID of the custom shipping method added by site admin for the same shipping zone (which is not visible to vendor). But I could not understand what does the instance ID 0 corresponds to?Moreover the custom shipping method added by vendor has the instance ID 22, which is not getting displayed at all.
Now I’m all the way more confused:
Why is it not getting called for instance ID 22?
Where is the instance ID 0 defined?
Why does it get displayed for other shipping methods (Flat Rate and Local Pickup)?
How do I avoid it getting executed multiple times?Hi @itzmekhokan,
I tried using the hook you suggested. In my shipping method’s constructor I wrote:
add_action('wcmp_vendor_shipping_methods_edit_form_fields', array($this, 'show_edit_form_fields'));
Now whatever I’m echoing from
show_edit_form_fields
gets displayed on edit shipping method dialog but it appears as many times as the number of shipping methods added by the vendor. And moreover it’s appearing for each of the shipping methods.For example – check this screenshot: https://prnt.sc/nbbury
The vendor has added 2 shipping methods: Flat Rate & my custom shipping method. If you see the test “does this show up?” is appearing twice at the bottom. And its appearing for Flat Rate as well.How do I know which shipping method is getting edited, the method ID and instance ID?
Hi @dualcube,
To understand how shipping method settings are shown in modal dialog, I’ve started implementing my own shipping method. I’m returning custom html from
generate_settings_html()
of my shipping method class. This html shows up for site admin (when I go to: WooCommerce > Settings > Shipping > Shipping Zones > my shipping zone > Edit my shipping method).But this custom HTML doesn’t show up for vendors (when I go to: Dashboard > Store Settings > Shipping > my shipping zone > Edit my shipping method). I get an empty modal dialog. What could be the reason and how do I show my custom HTML for vendors?
Yes, I agree with you Dan. And I know about
supports
property and its valuesinstance-settings
&instance-settings-modal
.But as I said, the WBS edit link takes the user to
wp-admin/admin.php?page=wc-settings&tab=shipping&instance_id=***
. This link works for site admin but doesn’t work for individual vendors. They don’t have access topage=wc-settings
.That’s where I’m looking for your help: can we have a different page to edit the WBS rules? This page will / should be accessible by all vendors. If we can have such a link, I can tweak the multivendor plugin (myself or ask the author) to take user to that page.
@dualcube One suggestion:
Whenever a hook is removed or changed, mention it in changelog.
Or otherwise implement a functionality like the one WooCommerce has implemented with WC_Deprecated_Hooks.
That will avoid confusion and help developers to quickly find alternative hooks.Ok. So as I understand, now we need to write the HTML for showing required fields, as compared to the earlier method where we just needed to pass the field configuration and the API will generate appropriate HTML.
Fine. Will use these. Thanks.
“Sold Individually” has a different purpose. Please check the tooltip for that field.
You will need to write some code to set a default value for stock quantity. No easy way, afaik.
It will be the site owner who will decide whether to allow selling of single quantity of any item or not (by defining it in Terms and Conditions). In the plugin there is no such restriction or setting from where this can be controlled.
In your example: John will need to register as a vendor and add cycle as a product with stock quantity set to 1. Once that item is sold out, the product will be marked as out of stock.Disclaimer: I’m not the plugin author. But I’ve been using WCMp for some time now and based on that knowledge I’ve tried to answer your question.
Great. Thanks for confirming. ??
I’ll write my code accordingly now.