This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function add_parent_styles() { | |
wp_enqueue_style('style', get_template_directory_uri() . '/style.css'); | |
} | |
add_action('wp_enqueue_scripts','add_parent_styles'); | |
// redirect to checkout after added to cart | |
add_filter( 'add_to_cart_redirect', 'woo_redirect_to_checkout' ); | |
function woo_redirect_to_checkout() { | |
global $woocommerce; | |
$checkout_url = $woocommerce->cart->get_checkout_url(); | |
return $checkout_url; | |
} | |
// custom message on checkout page | |
add_filter( 'wc_add_to_cart_message', 'woo_add_to_cart_message' ); | |
function woo_add_to_cart_message() { | |
global $woocommerce; | |
$message = __('Membership Selected for Purchase, fill out the form below and pay to gain access.', 'woocommerce' ); | |
return $message; | |
} | |
// change add to cart on shop page | |
add_filter( 'woocommerce_product_add_to_cart_text' , 'woo_product_add_to_cart_text' ); | |
function woo_product_add_to_cart_text() { | |
return __( 'Purchase Membership!', 'woocommerce' ); | |
} | |
// change add to cart message on product page | |
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 + | |
function woo_custom_cart_button_text() { | |
return __( 'Purchase Membership', 'woocommerce' ); | |
} | |
// remove not needed checkout fields | |
add_filter( 'woocommerce_checkout_fields' , 'woo_checkout_fields' ); | |
function woo_checkout_fields( $fields ) { | |
unset($fields['billing']['billing_last_name']); | |
unset($fields['billing']['billing_company']); | |
unset($fields['billing']['billing_address_1']); | |
unset($fields['billing']['billing_address_2']); | |
unset($fields['billing']['billing_city']); | |
unset($fields['billing']['billing_postcode']); | |
unset($fields['billing']['billing_country']); | |
unset($fields['billing']['billing_state']); | |
unset($fields['billing']['billing_phone']); | |
unset($fields['shipping']['shipping_first_name']); | |
unset($fields['shipping']['shipping_last_name']); | |
unset($fields['shipping']['shipping_company']); | |
unset($fields['shipping']['shipping_address_1']); | |
unset($fields['shipping']['shipping_address_2']); | |
unset($fields['shipping']['shipping_city']); | |
unset($fields['shipping']['shipping_postcode']); | |
unset($fields['shipping']['shipping_country']); | |
unset($fields['shipping']['shipping_state']); | |
unset($fields['order']['order_comments']); | |
return $fields; | |
} | |
// make it so only 1 item can be bought | |
add_filter( 'woocommerce_is_sold_individually', '__return_true'); | |
// disable additional information title | |
add_filter('woocommerce_enable_order_notes_field', '__return_false'); | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); | |
// remove login option on checkout | |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 ); | |
// remove tags and categories | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 ); | |
// remove breadcrumbs | |
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0); | |
// remove tabs | |
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10); | |
// remove sidebar | |
remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar', 10); | |
function woo_custom_detail_label( $translated_text, $text, $domain ) { | |
switch ( $translated_text ) { | |
case 'Billing Details' : | |
$translated_text = __( 'Fill out the Fields and Pay to Get Access to Our Content', 'woocommerce' ); | |
break; | |
case 'Your order' : | |
$translated_text = __( 'Here is a summary of your Members Access Purchase', 'woocommerce' ); | |
break; | |
} | |
return $translated_text; | |
} | |
add_filter( 'gettext', 'woo_custom_detail_label', 20, 3 ); | |
// hide quantity from checkout | |
add_filter('woocommerce_checkout_cart_item_quantity', '__return_false'); | |
// show message with checkout link if membership added twice | |
add_filter( 'woocommerce_add_to_cart_validation', 'woo_cart_items_custom_message' , 99, 3); | |
function woo_cart_items_custom_message( $valid, $product_id, $quantity ) { | |
global $woocommerce; | |
if($woocommerce->cart->cart_contents_count > 0){ | |
wc_add_notice( sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $woocommerce->cart->get_checkout_url(), __( 'Checkout.', 'woocommerce' ), sprintf( __( 'You have already selected a Unlimited Access %s to purchase.', 'woocommerce' ), 'Membership') ), 'error' ); | |
$valid = false; | |
} | |
return $valid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment