Using cookie values as dynamic Attribute the following way has the downside that with every Elementor Update the custom code we insert gets deleted and we have to insert it again after an update.
First download this „cookie.php“ file.
insert it in your hosting directory at:
httpdocs/wp-content/plugins/elementor-pro/modules/dynamic-tags
now add ‚Cookies‘, to wp-content/plugins/elementor-pro/modules/dynamic-tags/module.php in line 126 (see below)
add_component( 'acf', new ACF\Module() );
}
if ( function_exists( 'wpcf_admin_fields_get_groups' ) && API::is_licence_has_feature( self::LICENSE_FEATURE_TOOLSET_NAME, API::BC_VALIDATION_CALLBACK ) ) {
$this->add_component( 'toolset', new Toolset\Module() );
}
if ( function_exists( 'pods' ) && API::is_licence_has_feature( self::LICENSE_FEATURE_PODS_NAME, API::BC_VALIDATION_CALLBACK ) ) {
$this->add_component( 'pods', new Pods\Module() );
}
/*
* WooCommerce Add To Cart Dynamic Tag.
*
* The WC ATC Dynamic Tag returns a URL that adds items to a users cart
* via the URL parameters `?add-to-cart=' . $product_id . '&quantity=' . $quantity`.
* Normally this URL method redirects to the website's Home page after adding the items to
* the cart.
*
* Since the behavior of the Tag should be identical to the "Add to Cart" widget, clicking an
* element that is using the tag needs to redirect to the Single Product page for the added
* product or the Cart page after this process if the user selected that setting in WooCommerce.
*
* To accomplish that, an extra parameter in the URL ('&e-redirect=') is used. When this
* paramater is found, the WooCommerce Add to Cart Dynamic Tag will redirect to the
* appropriate page.
*/
//phpcs:ignore WordPress.Security.NonceVerification.Recommended -- The nonce is verified in the WC class.
$add_to_cart = Utils::_unstable_get_super_global_value( $_REQUEST, 'add-to-cart' );
//phpcs:ignore WordPress.Security.NonceVerification.Recommended -- The nonce is verified in the WC class.
$redirect = Utils::_unstable_get_super_global_value( $_REQUEST, 'e-redirect' );
if ( $add_to_cart && $redirect ) {
add_filter( 'woocommerce_add_to_cart_redirect', [ $this, 'filter_woocommerce_add_to_cart_redirect' ], 10, 1 );
}
}
public function filter_woocommerce_add_to_cart_redirect( $wc_get_cart_url ) {
//phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
return esc_url( Utils::_unstable_get_super_global_value( $_REQUEST, 'e-redirect' ) );
}
public function get_name() {
return 'tags';
}
public function get_tag_classes_names() {
return [
'Archive_Description',
'Archive_Meta',
'Archive_Title',
'Archive_URL',
'Author_Info',
'Author_Meta',
'Author_Name',
'Author_Profile_Picture',
'Author_URL',
'Comments_Number',
'Comments_URL',
'Page_Title',
'Post_Custom_Field',
'Post_Date',
'Post_Excerpt',
'Post_Featured_Image',
'Post_Gallery',
'Post_ID',
'Post_Terms',
'Post_Time',
'Post_Title',
'Post_URL',
'Site_Logo',
'Site_Tagline',
'Site_Title',
'Site_URL',
'Internal_URL',
'Current_Date_Time',
'Request_Parameter',
'Lightbox',
'Featured_Image_Data',
'Shortcode',
'Cookies',
'Contact_URL',
'User_Info',
'User_Profile_Picture',
];
}
public function get_groups() {
return [
self::POST_GROUP => [
'title' => esc_html__( 'Post', 'elementor-pro' ),
],
self::ARCHIVE_GROUP => [
'title' => esc_html__( 'Archive', 'elementor-pro' ),
],
self::SITE_GROUP => [
'title' => esc_html__( 'Site', 'elementor-pro' ),
],
self::MEDIA_GROUP => [
'title' => esc_html__( 'Media', 'elementor-pro' ),
],
self::ACTION_GROUP => [
'title' => esc_html__( 'Actions', 'elementor-pro' ),
],
self::AUTHOR_GROUP => [
'title' => esc_html__( 'Author', 'elementor-pro' ),
],
self::COMMENTS_GROUP => [
'title' => esc_html__( 'Comments', 'elementor-pro' ),
],
self::WOOCOMMERCE_GROUP => [
'title' => esc_html__( 'WooCommerce', 'elementor-pro' ),
],
];
}
}
In case you want to store Request Parameters as cookies to acces the Request-Parameter/Cookie Value from everywere within your site I have written a litte Article about it.