Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:25
Modify European country list for GDPR message bar restriction - WebToffee GDPR Cookie Consen
function wt_add_more_countries($country_list) {
array_push($country_list, 'CA');
return $country_list;
}
add_filter('wt_gdpr_eu_countrylist', 'wt_add_more_countries');
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:27
Alter subscription expiry date range - WooCommerce Subscriptions by WebToffeee
function wt_add_length( $subscription_ranges, $subscription_period ) {
$subscription_ranges['month'][25] = __('25 months', 'xa-woocommerce-subscriptions');
$subscription_ranges['month'][26] = __('26 months', 'xa-woocommerce-subscriptions');
$subscription_ranges['month'][27] = __('27 months', 'xa-woocommerce-subscriptions');
$subscription_ranges['month'][36] = __('36 months', 'xa-woocommerce-subscriptions');
return $subscription_ranges;
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:28
Hide cookie bar on selected pages - WebToffee GDPR Cookie Consent plugin
add_filter('cli_show_cookie_bar_only_on_selected_pages', 'webtoffee_custom_selected_pages', 10, 2);
function webtoffee_custom_selected_pages($html, $slug) {
$slug_array = array('sample-page', 'test-page', 'my*');
if (in_array($slug, $slug_array)) {
$html = '';
return $html;
}
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:29
Add more columns to Cookie Audit Table - WebToffee GDPR Cookie Consent Plugin
add_filter('cli_new_columns_to_audit_table','cli_add_new_columns',10,1);
function cli_add_new_columns($table)
{
$table .= '<th class="cookielawinfo-column-5">'.__('Cookie ID', 'cookie-law-info').'</th>';
$table .= '<th class="cookielawinfo-column-6">'.__('Cookie Sensitivity', 'cookie-law-info').'</th>';
return $table;
}
add_filter('cli_new_column_values_to_audit_table','cli_add_value_to_new_columns',10,2);
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:30
Make order status completed when an order is placed - WebToffee WooCommerce Subscriptions
add_action( 'woocommerce_order_status_processing', 'processing_to_completed');
function processing_to_completed($order_id){
$order = new WC_Order($order_id);
$order->update_status('completed');
}
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:32
Add custom columns into audit table - WebToffee GDPR Cookie Consent Plugin
add_filter('cli_new_columns_to_audit_table', 'wt_add_new_column',10,1);
function wt_add_new_column($table)
{
return $table .= '<th class="cookielawinfo-column-5">'.__('Cookie ID', 'cookie-law-info').'</th>';
}
add_filter('cli_new_column_values_to_audit_table','wt_add_new_value',10,2);
function wt_add_new_value($ret, $custom)
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 06:45
Add custom role to new members - WebToffee WooCommerce Memberships
add_filter('hf_memberships_new_membership_data', 'webtoffee_assign_role_after_membership');
function webtoffee_assign_role_after_membership($new_membership_data, $user_id_product_id_order_id) {
$theUser = new WP_User($user_id_product_id_order_id['user_id']);
$role = 'mycustomrole'; // string $role = Role name
$theUser->add_role($role);
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 07:00
Remove My-Account menu links - WebToffee WooCommerce Subscriptions
add_filter('woocommerce_account_menu_items', 'webtoffee_remove_my_account_links');
function webtoffee_remove_my_account_links($menu_links) {
unset($menu_links['subscriptions']); // Subscriptions
unset($menu_links['payment-methods']); // Payment methods
return $menu_links;
}
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 07:02
Redirect to custom page after successful purchase - WebToffee WooCommerce Subscriptions
add_action('template_redirect', 'webtoffee_custom_redirect_after_purchase');
function webtoffee_custom_redirect_after_purchase() {
global $wp;
if (is_checkout() && !empty($wp->query_vars['order-received'])) {
wp_redirect('http://www.webtoffee.com/'); // Redirect to your desired page here.
@webtoffee-git
webtoffee-git / functions.php
Created February 13, 2020 07:03
Change Add to cart button text only on shop page - WebToffee WooCommerce Subscription
add_filter('woocommerce_product_add_to_cart_text', 'webtoffee_archive_custom_addtocart_button_text', 10, 2);
function webtoffee_archive_custom_addtocart_button_text($var, $instance)
{
if(is_shop()){
$var = __('Read More', 'woocommerce');
}
return $var;