Created
September 10, 2016 19:06
-
-
Save ChrisFlannagan/bc781adc4fdd7cc6c963a950f29d62a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); | |
| function my_theme_enqueue_styles() { | |
| wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); | |
| } | |
| /** ========= ALL WOOCOMMERCE FUNCTIONALITY BELOW ========= */ | |
| /** | |
| * Clear cache on add to cart so the cart counter in header is updated | |
| */ | |
| add_action( 'woocommerce_add_to_cart', 'my_custom_clear_cache' ); | |
| function my_custom_clear_cache() { | |
| comet_cache::clear(); | |
| } | |
| /** | |
| * Filter our add to cart buttons | |
| */ | |
| add_filter( 'woocommerce_product_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text' ); | |
| function custom_woocommerce_product_add_to_cart_text() | |
| { | |
| global $product; | |
| $product_type = $product->product_type; | |
| switch ( $product_type ) { | |
| case 'external': | |
| return __( 'Buy product', 'woocommerce' ); | |
| break; | |
| case 'grouped': | |
| return __( 'View products', 'woocommerce' ); | |
| break; | |
| case 'simple': | |
| return __( 'Add to cart', 'woocommerce' ); | |
| break; | |
| case 'variable': | |
| return __( 'Select Options', 'woocommerce' ); | |
| break; | |
| case 'subscription': | |
| return __( 'Join Club', 'woocommerce' ); | |
| break; | |
| default: | |
| return __( 'Read more', 'woocommerce' ); | |
| } | |
| } | |
| /** | |
| * Add the SSN field to the checkout if Four Easy Payments is available | |
| */ | |
| add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' ); | |
| function my_custom_checkout_field( $checkout ) { | |
| echo '<div id="my_custom_checkout_field"><h2>' . __('Payment Plan Requirements') . '</h2>'; | |
| woocommerce_form_field('ssn_easypay', array( | |
| 'type' => 'text', | |
| 'label' => __('Credit Check'), | |
| 'placeholder' => __('Social Security Number'), | |
| ), $checkout->get_value('ssn_easypay')); | |
| echo '</div>'; | |
| } | |
| /** | |
| * Process the checkout with SSN | |
| */ | |
| add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); | |
| function my_custom_checkout_field_process() { | |
| // Check if set, if its not set add an error. | |
| if ( ! $_POST['ssn_easypay'] ) | |
| wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' ); | |
| } | |
| /** | |
| * Change tab text on product pages | |
| */ | |
| /* | |
| add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 ); | |
| function woo_rename_tabs($tabs) | |
| { | |
| $tabs['reviews']['title'] = __( 'Feedback' ); // Rename the reviews tab | |
| $tabs['additional_information']['title'] = __( 'How To' ); // Rename the additional information tab | |
| return $tabs; | |
| } | |
| */ | |
| /** | |
| * ========================= | |
| * WOOCOMMERCE SUBSCRIPTIONS | |
| * ========================= | |
| */ | |
| /** | |
| * Only allow one Subscription at a time | |
| * Useful if using subscriptions as a payment plan instead of just an unlimited subscription | |
| * | |
| * ========================= | |
| * FUNKY WHEN AJAX IS ON | |
| * ========================= | |
| * | |
| */ | |
| add_filter( 'woocommerce_add_to_cart_validation', 'woo_block_sub', 10, 2 ); | |
| function woo_block_sub( $valid, $product_id ) { | |
| // Get the current product | |
| $current_product = wc_get_product( $product_id ); | |
| // See if the current product user's are viewing is a subscription product | |
| if ( $current_product instanceof WC_Product_Subscription || $current_product instanceof WC_Product_Variable_Subscription ) { | |
| foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { | |
| // Loop through all products in the cart | |
| $_product | |
| = $values['data']; | |
| // Check if current item is a subscription type | |
| if( $_product instanceof WC_Product_Subscription || $_product instanceof WC_Product_Subscription_Variation ) { | |
| // Display a notice and cancel the addition of item to cart | |
| wc_add_notice( "Only one subscription can be purchased." ); | |
| return false; | |
| } | |
| } | |
| } | |
| return $valid; | |
| } | |
| /** Rakuten or any detailed conversion pixels */ | |
| /* | |
| add_action('woocommerce_thankyou', 'Rakuten_Pixel'); | |
| function Rakuten_Pixel( $order_id ) | |
| { | |
| // Grab the order | |
| $order = new WC_Order( $order_id ); | |
| // Get _rakuten_pixel | |
| $orderPixeled = get_post_meta( $order_id, '_rakuten_pixel', true ); | |
| if ( $order->status != 'failed' && $orderPixeled != 'yes' ) { | |
| // Update _rakuten_pixel. blocks pixel fire if page is relaoded | |
| update_post_meta( $order_id, '_rakuten_pixel', 'yes' ); | |
| // Grab order currency | |
| $orderCurrency = $order->get_order_currency(); | |
| // Products | |
| $orderLineitem = $order->get_items(); | |
| // Order total | |
| $orderTotal = $order->get_total(); | |
| // Building array of line items | |
| $qlist = ''; | |
| $amtlist = ''; | |
| $skulist = ''; | |
| $namelist = ''; | |
| foreach ( $orderLineitem as $item_id => $item ) { | |
| $cartProduct = $order->get_product_from_item( $item ); | |
| $qlist .= $item['qty'] . "|"; | |
| $amtlist .= $order->get_line_subtotal($item) * 100 . "|"; | |
| $skulist .= urlencode( $cartProduct->get_sku() ) . "|"; | |
| $namelist .= urlencode( $cartProduct->get_title() ) . "|"; | |
| } | |
| // Removing pipe sysmbol at the end of each line | |
| $qlist = substr($qlist, 0, -1); | |
| $amtlist = substr($amtlist, 0, -1); | |
| $skulist = substr($skulist, 0, -1); | |
| $namelist = substr($namelist, 0, -1); | |
| // Dicount accounting | |
| if ( $order->get_used_coupons() ) { | |
| $discountCode = $order->get_used_coupons(); | |
| $discountAmount = $order->get_total_discount() * 100; | |
| $qlist .= "|0"; | |
| $amtlist .= "|-" . $discountAmount; | |
| $skulist .= "|Discount"; | |
| $namelist .= "|Discount Code: " . urlencode( $discountCode ); | |
| } | |
| // Pixel | |
| $mid = '37967'; | |
| echo '<img src="https://track.linksynergy.com/ep?mid=' . $mid . '&ord=' . $order_id . '&skulist=' . $skulist . '&qlist=' . $qlist . '&amtlist=' . $amtlist . '&cur=' . $orderCurrency . '&img=1&namelist=' . $namelist . '" />'; | |
| echo '<iframe src="https://forwardrocketlaunch.com/p.ashx?o=10945&e=555&t=' . $order_id . '&p=' . $orderTotal . '" height="1" width="1" frameborder="0"></iframe>'; | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment