Woocommerce checkout: Moving an opt-in field right under the e-mail-field - email

So I used code snippets successfully for moving checkout fields around, for example moving the e-mail-field on first position with this code:
add_filter( 'woocommerce_billing_fields', 'bbloomer_move_checkout_email_field' );
function bbloomer_move_checkout_email_field( $address_fields ) {
$address_fields['billing_email']['priority'] = 1;
return $address_fields;
}
But what I want to do now by using code snippets, is to move an opt-in consent field right under the e-mail-field that I positioned with the code above.
https://i.postimg.cc/CLZdk54r/fdfdfdffdf.png
The classes of this opt-in-flied are: growmatik_consent_wc_checkout and the outer one growmatik-consent.
I tried a couple of things, but nothing went successfully.
The following code seems to do what I want to accomplish with the klaviyo opt in and the flow-checkout plugin (added to this path: wp-content/plugins/fluid-checkout/inc/checkout-steps.php), I guess it could be re-written so that it works from the normal functions.php and with the growmatik-consent class instead of the "kl_newsletter_checkbox" class:
/**
* Return list of checkout fields for contact step.
*/
public function get_contact_step_display_field_ids() {
return apply_filters( 'fc_checkout_contact_step_field_ids', array(
'billing_email','kl_newsletter_checkbox'
) );
}
I don’t know if you would need anything else and if you even can help me, but it would be really amazing!
Here is a staging of the page where you could actually go to the checkout:
https://wordpress-858200-3004984.cloudwaysapps.com/index.php/product/patterned-wrap-dress/
Thank you so much for your time and maybe even answer!
With kind regards
Chris

Related

How can I use a gravity forms function for a specific form?

I have the following code which helps me to move the deleted gravity forms entries to trash instead of deleteting them permanently at gravityview panel. I have multiple forms, I just need this code to be applied on a specific form, not for all other forms. How can I do that?
Note: I am not much good with coding, helping to understand will be highly appreciated.
if ( ! defined( 'WPINC' ) ){
die;
}
add_filter( 'gravityview/delete-entry/mode', '_gravityview_delete_entry_mode_return_trash' );
function _gravityview_delete_entry_mode_return_trash( $mode = 'delete' ) {
return 'trash';
}
Just a quick note: the original snippet was posted on official gravityview site here: https://docs.gravitykit.com/article/299-change-the-delete-entry-mode-from-delete-to-trash if this helps.
Thank you.

Custom moodle completion rule does not work

I am developing a mod_plugin for Moodle and want to support the automatic activity completion with a custom rule. I followed the official documentation and implemented all necessary functions. In the lib.php [pluginname]_supports method I have registered, FEATURE_GRADE_HAS_GRADE, FEATURE_COMPLETION_TRACKS_VIEWS, FEATURE_COMPLETION_HAS_RULES.
The \mod_[pluginname]\completion\custom_completion class defines a custom rule named "completiontest" in get_defined_custom_rules(). During my tests I found out that the methods get_state(), get_sort_order() and get_custom_rule_descriptions() are never executed. Also I don't see any output via activity_information().
I have cleared all caches, created new instances of my activity module, with no result. My development environment uses Moodle 3.11.7 (Build: 20220509).
My custom_completion.php script:
<?php
declare(strict_types=1);
namespace mod_cwr\completion;
use core_completion\activity_custom_completion;
class custom_completion extends activity_custom_completion {
public function get_state(string $rule): int {
return COMPLETION_INCOMPLETE;
}
public static function get_defined_custom_rules(): array {
return [
'completiontest'
];
}
public function get_custom_rule_descriptions(): array {
return [
'completiontest' => 'testout'
];
}
public function get_sort_order(): array {
return [
'completionview',
'completiontest',
'completionusegrade'
];
}
}
Test at the view.php:
$completion = new completion_info($course);
$completion->set_module_viewed($coursemodule);
if($completion->is_enabled($coursemodule) == COMPLETION_TRACKING_AUTOMATIC){
$completion->update_state($coursemodule, COMPLETION_INCOMPLETE, $USER->id);
}
$completiondetails = \core_completion\cm_completion_details::get_instance($coursemodule, $USER->id);
$activitydates = \core\activity_dates::get_dates_for_module($coursemodule, $USER->id);
echo $OUTPUT->activity_information($coursemodule, $completiondetails, $activitydates);
At the mod_form.php I check with completion_rule_enabled() if a custom rule is activated by the settings.
Does anyone have any idea what the problem could be?
Looking at the mod_forum plugin code showed me, that the get_state($rule) method does not observe all custom rules, only those selected in the settings. How do I tell Moodle to use a specific custom rule?
You appear to be calling update_state() and passing in the possible state change as COMPLETION_INCOMPLETE.
This is a way of telling Moodle "if the state is already incomplete, don't bother doing any expensive completion calculations to check if it should change state".
If you want Moodle to check and then (potentially) change the state to "complete", then pass COMPLETION_COMPLETE. If you really don't know which way it could be switching, then leave the param at the default COMPLETION_UNKNOWN (a good example would be forum completion - if you have just created a forum post, then you might cause the forum to be marked as "complete", but you certainly can't cause the forum to be marked as "incomplete", so you can pass the COMPLETION_COMPLETE parameter, so Moodle knows it only needs to check for changes if the forum is not already "complete").
Also, don't bother passing $USER->id as the third parameter - that's the default which is used of you don't pass anything.
As for telling Moodle which rules to use - it is up to you, when your function is called, to check your plugins settings to determine which rules are in use (and any other relevant configuration - e.g. with mod_forum, it needs to check how many posts are required for completion).
Thank you for the support. Got it running.
I now use $completion->update_state($coursemodule, COMPLETION_COMPLETE); and also had to fix [pluginname]_get_coursemodule_info() with $result->customdata['customcompletionrules']['completiontest'] = $cwr->completiontest; and totally forgot the return $result;.

cakephp 3.0 'App\Controller\ContactForm' not found modelless form

I am trying to create a modelless form using cakePHP 3.0, I have been following the guide through the cookbook here http://book.cakephp.org/3.0/en/core-libraries/form.html but it seems I am getting confused as to where to put ContactForm.php. It says to put it in src/Form/ContactForm.php but it did not work. Can someone direct me to this? Thanks
Pls, provide a bit more info about your problem
1) is ContactForm recognized in controller?
if not - check namespace
2) handle your data only in
protected function _execute(array $data)
{
// Send an email.
return true;
}
not in controller's
if ($this->request->is('post')) {
if ($contact->execute($this->request->data)) {
//NOT HERE!!!
} else {
// error
}
}
Also bear in mind that your server configuration may forbid php short open tags.
Make sure your class starts with <?php and not only <? to be on the safer side. If not, CakePHP will simply respond by the Your\Namespace\Class Not Found message.
Just verify where you have put Form Folder, it must be inside src Folder.
Also be sure that the class has Form as suffix.
Because your error is App\Controller\ContactForm not found, that means that you have NOT put Form Folder inside src Folder.

user_work_history with Flex and the ActionScript SDK

I'm working on a sample app for Facebook, using Flash Builder and Flex.
Now, I've got everything up and running - but there's one problem, specifically with the work history part.
When I try to display the user's work history..here's the code for logging in:
protected function login():void
{
FacebookDesktop.login(loginHandler, ["user_birthday", "user_work_history"]);
}
Here, loginHandler's a callback function, that then goes ahead and displays data about the user:
protected function loginHandler(success:Object,fail:Object):void
{
if (success){
currentState = "LoggedIn";
fname.text = success.user.name;
userImg.source=FacebookDesktop.getImageUrl(success.uid,"small");
birthdayLbl.text=success.user.birthday;
workLbl.text=success.user.work;
}
}
Now, the problem occurs with success.user.work - it ends up printing the following:
[object,Object],[object,Object],[object,Object],[object,Object]
Obviously, I'm doing something wrong..but I can't figure out what exactly it is. Would be grateful for some pointers!
Thanks!
Rudi.
The object contained in success.user.work is most likely an array of objects, each item representing a work period, so you'll have to treat it as such. Either use a list and a custom renderer for each item, or create a string by iterating over the array, and appending the fields that you're interested in.
To see what the individual objects contain, either use a breakpoint during debug and inspect them, or check to see if they're documented in the facebook development documentation.

Joomla: Is there a module render plugin event?

Due to some caching issues, I need to explicitly bypass the cache, for a specific module, if certain URL parameters are present. The workaround I've arrived at is to hack the render() function in libraries/joomla/document/html/renderer/module.php, along the lines of:
function render( $module, $params = array(), $content = null )
{
// Existing code:
$mod_params = new JParameter( $module->params );
// My hack:
if ($module->module == 'mod_foo')
{
if (certain URL parameters are present)
{
$mod_params->set('cache', 0);
}
}
...
}
Of course, hacking the core joomla code is a terrible idea, one which I'd like to avoid if at all possible. So, is there an appropriate hook I can plugin to in order to achieve the same? I don't think I can do anything at the module level, since it won't even be inspected if the renderer has already decided to fetch it from cache.
To answer the first question no there isn't a module render event, here's the plugin doc's and the list of events in Joomla!
Turn off caching for your module.
See this article on The Art Of Joomla, additional articles you could look at:
Using Cache to Speed Up your code
JCache API