Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*** Child Theme Function ***/
- function depot_mikado_child_theme_enqueue_scripts() {
- $parent_style = 'depot_mikado_default_style';
- wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css');
- wp_enqueue_style('depot_mikado_child_style',
- get_stylesheet_directory_uri() . '/style.css',
- array($parent_style),
- wp_get_theme()->get('Version')
- );
- }
- add_action( 'wp_enqueue_scripts', 'depot_mikado_child_theme_enqueue_scripts' );
- // Register and load the widget
- function wwpb_load_widget() {
- register_widget( 'wwpb_widget' );
- }
- add_action( 'widgets_init', 'wwpb_load_widget' );
- // Creating the widget
- class wwpb_widget extends WP_Widget {
- function __construct() {
- parent::__construct(
- // Base ID of your widget
- 'wwpb_widget',
- // Widget name will appear in UI
- __('Add redemption codes', 'wwpb_widget_domain'),
- // Widget description
- array( 'description' => __( 'Admin link to add redemption codes', 'wwpb_widget_domain' ), )
- );
- }
- // Creating widget front-end
- public function widget( $args, $instance ) {
- echo $args['before_widget']; ?>
- <div class="mkd-shopping-cart-holder mkd-cart-info-is-active" style="display: table-cell; min-height: 97px;" >
- <div class="mkd-shopping-cart">
- <a class="mkd-header-cart" href="<?php echo esc_url( home_url( '/product-category/admin/' ) ); ?>">
- <span class="mkd-cart-icon-text">REDEMPTION CODES</span>
- </a>
- </div>
- </div>
- <?php echo $args['after_widget'];
- }
- // Widget Backend
- public function form( $instance ) {
- if ( isset( $instance[ 'title' ] ) ) {
- $title = $instance[ 'title' ];
- }
- else {
- $title = __( 'New title', 'wpb_widget_domain' );
- }
- // Widget admin form
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
- </p>
- <?php
- }
- // Updating widget replacing old instances with new
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
- return $instance;
- }
- } // Class wpb_widget ends here
- // Register and load the widget
- function wpb_load_widget() {
- register_widget( 'wpb_widget' );
- }
- add_action( 'widgets_init', 'wpb_load_widget' );
- // Creating the widget
- class wpb_widget extends WP_Widget {
- function __construct() {
- parent::__construct(
- // Base ID of your widget
- 'wpb_widget',
- // Widget name will appear in UI
- __('Redemption Codes', 'wpb_widget_domain'),
- // Widget description
- array( 'description' => __( 'Display redemption codes', 'wpb_widget_domain' ), )
- );
- }
- // Creating widget front-end
- public function widget( $args, $instance ) {
- echo $args['before_widget']; ?>
- <div class="mkd-shopping-cart-holder mkd-cart-info-is-active" style="padding: 35px;">
- <div class="mkd-shopping-cart">
- <a class="mkd-header-cart" href="<?php echo esc_url( home_url( '/' ) ); ?>">
- <span class="mkd-cart-icon-text">MY ACCOUNT</span>
- </a>
- <div class="mkd-shopping-cart-dropdown">
- <ul id="nav_voucher">
- <?php do_action("giftbal"); ?>
- </ul>
- <div class="mkd-cart-bottom" style="padding: 0px 25px 20px 25px; height: auto;">
- <div class="mkd-btn-holder clearfix" style="margin-top: -15px !important;">
- <a itemprop="url" href="<?php echo esc_url( home_url( '/customer-logout' ) ); ?>" class="mkd-view-cart" data-title="LOGOUT" style="border: 1px solid #7b7b7b;"><span>LOGOUT</span></a>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?php echo $args['after_widget'];
- }
- // Widget Backend
- public function form( $instance ) {
- if ( isset( $instance[ 'title' ] ) ) {
- $title = $instance[ 'title' ];
- }
- else {
- $title = __( 'New title', 'wpb_widget_domain' );
- }
- // Widget admin form
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
- </p>
- <?php
- }
- // Updating widget replacing old instances with new
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
- return $instance;
- }
- } // Class wpb_widget ends here
- function authorize_less($available_gateways) {
- $maximum = 0;
- if ( WC()->cart->total < $maximum ) {
- unset( $available_gateways['authorizenet'] );
- }
- return $available_gateways;
- }
- add_filter( 'woocommerce_available_payment_gateways', 'authorize_less');
- add_action( 'woocommerce_cart_calculate_fees' , 'authorize_less' );
- add_action( 'woocommerce_after_cart_item_quantity_update', 'authorize_less' );
- function authorize_more($available_gateways) {
- $maximum = 0;
- if ( WC()->cart->total > $maximum ) {
- unset( $available_gateways['cod'] );
- }
- return $available_gateways;
- }
- add_filter( 'woocommerce_available_payment_gateways', 'authorize_more');
- add_action( 'woocommerce_cart_calculate_fees' , 'authorize_more' );
- add_action( 'woocommerce_removed_coupon', 'authorize_more' );
- add_action('pre_get_posts', 'wpse223576_search_woocommerce_only');
- function wpse223576_search_woocommerce_only( $query ) {
- if( ! is_admin() && is_search() && $query->is_main_query() ) {
- $query->set( 'post_type', 'product' );
- }
- }
- add_action('init', 'woocommerce_clear_cart_url');
- function woocommerce_clear_cart_url() {
- global $woocommerce;
- if( isset($_REQUEST['clear-cart']) ) {
- $woocommerce->cart->empty_cart();
- }
- }
- function iconic_bypass_logout_confirmation() {
- global $wp;
- if ( isset( $wp->query_vars['customer-logout'] ) ) {
- wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
- exit;
- }
- }
- add_action( 'template_redirect', 'iconic_bypass_logout_confirmation' );
- function cart_update_script() {
- if (is_checkout()) :
- ?>
- <script>
- jQuery( function( $ ) {
- // woocommerce_params is required to continue, ensure the object exists
- if ( typeof woocommerce_params === 'undefined' ) {
- return false;
- }
- $checkout_form = $( 'form.checkout' );
- $checkout_form.on( 'change', 'input[name="payment_method"]', function() {
- $checkout_form.trigger( 'update' );
- });
- });
- </script>
- <?php
- endif;
- }
- add_action( 'wp_footer', 'cart_update_script', 999 );
- // WooCommerce Rename Checkout Fields
- add_filter( 'woocommerce_checkout_fields' , 'custom_rename_wc_checkout_fields' );
- // Change placeholder and label text
- function custom_rename_wc_checkout_fields( $fields ) {
- $fields['shipping']['shipping_address_2']['label'] = '<i style="font-size: 12px;">For proper delivery, PO Box not accepted</i>';
- return $fields;
- }
- // rename the "Have a Coupon?" message on the checkout page
- function woocommerce_rename_coupon_message_on_checkout() {
- return 'Have a redemption code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';
- }
- add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );
- // rename the coupon field on the checkout page
- function woocommerce_rename_coupon_field_on_checkout( $translated_text, $text, $text_domain ) {
- // bail if not modifying frontend woocommerce text
- if ( is_admin() || 'woocommerce' !== $text_domain ) {
- return $translated_text;
- }
- if ( 'Coupon code' === $text ) {
- $translated_text = 'Redemption Code';
- } elseif ( 'Apply Coupon' === $text ) {
- $translated_text = 'Apply Code';
- }
- return $translated_text;
- }
- add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_checkout', 10, 3 );
- function my_wp_nav_menu_args( $args = '' ) {
- if( is_user_logged_in() ) {
- $args['menu'] = 'main-menu-header';
- } else {
- $args['menu'] = 'main';
- }
- return $args;
- }
- add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
- add_action( 'woocommerce_order_status_processing', 'coupon_email_restriction_on_purchase', 20, 2 );
- function coupon_email_restriction_on_purchase( $order_id, $order ) {
- $applied_coupons = $order->get_used_coupons();
- if( count( $applied_coupons ) == 0 )
- return; // Exit if there is no coupons
- // Get the Customer billing email
- $customer_email = $order->get_billing_email();
- foreach( $applied_coupons as $coupon_code ){
- // Get an instance of the WC_Coupon object
- $coupon = new WC_Coupon( $coupon_code );
- // Get email restrictions (even if is an empty array)
- $email_restrictions = $coupon->get_email_restrictions();
- // Add the customer email to the restrictions array
- $email_restrictions[] = $customer_email;
- // set the new array of email restrictions
- $coupon->set_email_restrictions( $email_restrictions );
- // Save the coupon data
- $coupon->save();
- }
- }
- add_filter( 'woocommerce_cart_subtotal', 'bbloomer_slash_cart_subtotal_if_discount', 99, 3 );
- function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $obj ){
- global $woocommerce;
- if ( WC()->cart->total > 0 ) {
- $new_cart_subtotal = wc_price( WC()->cart->subtotal - $woocommerce->cart->get_cart_discount_tax_total() - $woocommerce->cart->get_cart_discount_total() );
- $cart_subtotal = sprintf( '<del>%s</del> <b>%s</b>', $cart_subtotal , $new_cart_subtotal );
- }
- return $cart_subtotal;
- }
- function wpse_131562_redirect() {
- if (
- ! is_user_logged_in()
- && (is_woocommerce() || is_cart() || is_checkout())
- ) {
- // feel free to customize the following line to suit your needs
- wp_redirect(home_url());
- exit;
- }
- }
- add_action('template_redirect', 'wpse_131562_redirect');
- if (!function_exists('depot_mikado_woocommerce_cart_back_to_home')) {
- function depot_mikado_woocommerce_cart_back_to_home(){
- print '<a class="mkd-cart-go-back" itemprop="url" href="' . esc_url(home_url('/shop')) . '">' . esc_html__('Continue shopping', 'depot') . '</a>';
- }
- }
- function wooc_extra_register_fields() {
- ?>
- <p class="form-row form-row-wide">
- <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?> <span class="required">*</span></label>
- <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="" />
- <?php
- }
- add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
- add_action( 'woocommerce_edit_account_form', 'wooc_extra_register_fields');
- /**
- * Validate the extra register fields.
- *
- * @param string $username Current username.
- * @param string $email Current email.
- * @param object $validation_errors WP_Error object.
- *
- * @return void
- */
- function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
- if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
- $validation_errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Phone is required!.', 'woocommerce' ) );
- }
- }
- add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
- add_action( 'woocommerce_edit_account_form', 'wooc_validate_extra_register_fields', 10, 3 );
- /**
- * Save the extra register fields.
- *
- * @param int $customer_id Current customer ID.
- *
- * @return void
- */
- function wooc_save_extra_register_fields( $customer_id ) {
- if ( isset( $_POST['billing_phone'] ) ) {
- // WooCommerce billing phone
- update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
- }
- }
- add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
- add_action( 'woocommerce_save_account_details', 'wooc_save_extra_register_fields' );
- function custom_scripts() {
- wp_enqueue_script( 'cust-js', get_stylesheet_directory_uri() . '/custom.js', array('jquery'), '20180101', true );
- }
- // add_action( 'wp_enqueue_scripts', 'custom_scripts' );
- // @to-do potential starting point for tax work below commented out
- // https://docs.woocommerce.com/wc-apidocs/class-WC_Cart.html
- //
- // We want to apply taxable percentage to only remaining ammount if a
- // coupon is used on a transaction.
- // 1) Get coupon\s total
- // 2) Get subtotal
- // 3) Adjust new total to be minus coupon ammount
- // 4) If a positive value tax that amount
- // 5) Update/return
- //
- //add_action( 'woocommerce_calculate_totals', 'custom_cart_calculate_totals', 10, 1 );
- function custom_cart_calculate_totals( $cart_object ) {
- if ( !WC()->cart->is_empty() ){
- // check for whatever flags the taxes to be applied
- $flagForTaxes = true; // set to true for testing
- if($flagForTaxes){
- // get total of coupons
- $coupons = WC()->cart->get_coupon_discount_totals();
- $subtotal = WC()->cart->get_subtotal();
- $shipping = WC()->cart->get_shipping_total();
- // $total = ($subtotal - $coupons);
- // WC()->cart->set_total(1.11);
- // return $total;
- }
- }
- }
- $new_cart_subtotal = wc_price( WC()->cart->subtotal - $woocommerce->cart->get_cart_discount_total() );
- //add_filter( 'woocommerce_cart_total', 'bbloomer_slash_cart_subtotal_if_discount', 99, 3 );
- function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $obj ){
- global $woocommerce;
- if ( WC()->cart->total > 0 ) {
- $new_cart_subtotal = $woocommerce->cart->subtotal - $woocommerce->cart->get_cart_discount_total() ;
- $cart_subtotal = sprintf( '<del>%s</del> <b>%s</b>', $cart_subtotal , $new_cart_subtotal );
- }
- return $cart_subtotal;
- }
- add_filter( 'woocommerce_cart_total', 'bbloomer_slash_cart_subtotal_if_discount', 99, 3 );
- function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $obj ){
- global $woocommerce;
- if ( !WC()->cart->is_empty() ) {
- $new_cart_subtotal = $woocommerce->cart->subtotal - $woocommerce->cart->get_cart_discount_total() ;
- $cart_total = $new_cart_subtotal;
- }
- return $cart_total;
- }
- function authorize_more($available_gateways) {
- $maximum = 0;
- if ( WC()->cart->total > $maximum ) {
- unset( $available_gateways['cod'] );
- }
- return $available_gateways;
- }
- add_filter( 'woocommerce_available_payment_gateways', 'authorize_more');
- add_action( 'woocommerce_cart_calculate_fees' , 'authorize_more' );
- add_action( 'woocommerce_removed_coupon', 'authorize_more' );
- function authorize_less($available_gateways) {
- $maximum = 0;
- if ( WC()->cart->total < $maximum ) {
- unset( $available_gateways['authorizenet'] );
- }
- return $available_gateways;
- }
- add_filter( 'woocommerce_available_payment_gateways', 'authorize_less');
- add_action( 'woocommerce_cart_calculate_fees' , 'authorize_less' );
- add_action( 'woocommerce_after_cart_item_quantity_update', 'authorize_less' );
- add_filter( 'woocommerce_cart_total', 'bbloomer_slash_cart_subtotal_if_discount', 99, 3 );
- function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $obj ){
- global $woocommerce;
- if ( !WC()->cart->is_empty() ) {
- $new_cart_subtotal = $woocommerce->cart->subtotal - $woocommerce->cart->get_cart_discount_total();
- $cart_total = $woocommerce->cart->get_cart_discount_total();
- }
- return $cart_total;
- }
Add Comment
Please, Sign In to add comment