diff --git a/pmpro-shipping.php b/pmpro-shipping.php old mode 100755 new mode 100644 index 2a97c96..ca04086 --- a/pmpro-shipping.php +++ b/pmpro-shipping.php @@ -3,7 +3,7 @@ Plugin Name: Paid Memberships Pro - Shipping Add On Plugin URI: https://www.paidmembershipspro.com/add-ons/shipping-address-membership-checkout/ Description: Add shipping to the checkout page and other updates. -Version: .8 +Version: 1.0 Author: Paid Memberships Pro Author URI: https://www.paidmembershipspro.com Text Domain: pmpro-shipping @@ -12,13 +12,13 @@ if(!defined('PMPRO_SHIPPING_SHOW_REQUIRED')) define( 'PMPRO_SHIPPING_SHOW_REQUIRED', true ); //if false required fields won't have asterisks and non-required fields will say (optional) -define( 'PMPRO_SHIPPING_VERSION', '.8' ); +define( 'PMPRO_SHIPPING_VERSION', '1.0' ); -/** - * Load plugin textdomain. +/** + * Load plugin textdomain. */ function pmproship_pmpro_load_textdomain() { - load_plugin_textdomain( 'pmpro-shipping', false, basename( dirname( __FILE__ ) ) . '/languages' ); + load_plugin_textdomain( 'pmpro-shipping', false, basename( dirname( __FILE__ ) ) . '/languages' ); } add_action( 'init', 'pmproship_pmpro_load_textdomain' ); @@ -118,8 +118,8 @@ class="input " size="30" ?> * - - + + " size="30" function pmproship_pmpro_checkout_preheader() { global $sameasbilling, $sfirstname, $slastname, $saddress1, $saddress2, $scity, $sstate, $szipcode, $sphone, $scountry, $shipping_address, $pmpro_requirebilling, $current_user; - + if ( ! empty( $_REQUEST['sameasbilling'] ) ) { $sameasbilling = true; } //we'll get the fields further down below @@ -146,9 +146,9 @@ function pmproship_pmpro_checkout_preheader() $saddress2 = sanitize_text_field( $_REQUEST['saddress2'] ); } $scity = sanitize_text_field( $_REQUEST['scity'] ); - + $sstate = sanitize_text_field( $_REQUEST['sstate'] ); - + //convert long state names to abbreviations if ( ! empty( $sstate ) ) { global $pmpro_states; @@ -159,7 +159,7 @@ function pmproship_pmpro_checkout_preheader() } } } - + $sphone = sanitize_text_field( $_REQUEST['sphone'] ); $szipcode = sanitize_text_field( $_REQUEST['szipcode'] ); $scountry = sanitize_text_field( $_REQUEST['scountry'] ); @@ -178,7 +178,7 @@ function pmproship_pmpro_checkout_preheader() $sstate = sanitize_text_field( $_SESSION['sstate'] ); $sphone = sanitize_text_field( $_SESSION['sphone'] ); $szipcode = sanitize_text_field( $_SESSION['szipcode'] ); - $scountry = sanitize_text_field( $_SESSION['scountry'] ); + $scountry = sanitize_text_field( $_SESSION['scountry'] ); } else if ( ! empty( $current_user->ID ) ) { //get shipping fields from user meta $user_id = $current_user->ID; @@ -191,7 +191,7 @@ function pmproship_pmpro_checkout_preheader() $szipcode = get_user_meta( $user_id, "pmpro_szipcode", true ); $sphone = get_user_meta( $user_id, "pmpro_sphone", true ); $scountry = get_user_meta( $user_id, "pmpro_scountry", true ); - } + } } add_action('pmpro_checkout_preheader', 'pmproship_pmpro_checkout_preheader'); @@ -205,9 +205,9 @@ function pmproship_pmpro_checkout_preheader() function pmproship_pmpro_checkout_preheader_check_gateway() { //if we're not going offsite, we don't need to save things in session global $gateway; - + if( 1 === preg_match( '/paypalstandard|paypalexpress|twocheckout|ccbill|payfast/i', $gateway ) ) { - add_action('pmpro_checkout_before_change_membership_level', 'pmproship_save_shipping_to_usermeta', 1); + add_action('pmpro_checkout_before_change_membership_level', 'pmproship_save_shipping_to_usermeta', 1); } else { add_action('pmpro_after_checkout', 'pmproship_save_shipping_to_usermeta'); } @@ -218,37 +218,37 @@ function pmproship_pmpro_checkout_preheader_check_gateway() { * Update a user meta values. */ function pmproship_save_shipping_to_usermeta($user_id) -{ - global $sameasbilling, $sfirstname, $slastname, $saddress1, $saddress2, $scity, $sstate, $szipcode, $sphone, $scountry, $shipping_address, $pmpro_requirebilling; - +{ + global $sameasbilling, $sfirstname, $slastname, $saddress1, $saddress2, $scity, $sstate, $szipcode, $sphone, $scountry, $shipping_address, $pmpro_requirebilling; + if(!empty($sameasbilling)) - { - //set the shipping fields to be the same as the billing fields + { + //set the shipping fields to be the same as the billing fields $sfirstname = get_user_meta($user_id, "pmpro_bfirstname", true); $slastname = get_user_meta($user_id, "pmpro_blastname", true); $saddress1 = get_user_meta($user_id, "pmpro_baddress1", true); $saddress2 = get_user_meta($user_id, "pmpro_baddress2", true); $scity = get_user_meta($user_id, "pmpro_bcity", true); $sstate = get_user_meta($user_id, "pmpro_bstate", true); - $szipcode = get_user_meta($user_id, "pmpro_bzipcode", true); - $sphone = get_user_meta($user_id, "pmpro_bphone", true); - $scountry = get_user_meta($user_id, "pmpro_bcountry", true); + $szipcode = get_user_meta($user_id, "pmpro_bzipcode", true); + $sphone = get_user_meta($user_id, "pmpro_bphone", true); + $scountry = get_user_meta($user_id, "pmpro_bcountry", true); } - + if(!empty($saddress1)) { //update the shipping user meta update_user_meta($user_id, "pmpro_sfirstname", $sfirstname); - update_user_meta($user_id, "pmpro_slastname", $slastname); + update_user_meta($user_id, "pmpro_slastname", $slastname); update_user_meta($user_id, "pmpro_saddress1", $saddress1); update_user_meta($user_id, "pmpro_saddress2", $saddress2); update_user_meta($user_id, "pmpro_scity", $scity); update_user_meta($user_id, "pmpro_sstate", $sstate); - update_user_meta($user_id, "pmpro_szipcode", $szipcode); - update_user_meta($user_id, "pmpro_sphone", $sphone); - update_user_meta($user_id, "pmpro_scountry", $scountry); + update_user_meta($user_id, "pmpro_szipcode", $szipcode); + update_user_meta($user_id, "pmpro_sphone", $sphone); + update_user_meta($user_id, "pmpro_scountry", $scountry); } - + //unset session vars $vars = array('sfirstname', 'slastname', 'saddress1', 'saddress2', 'scity', 'sstate', 'szipcode', 'sphone', 'scountry', 'sameasbilling'); foreach($vars as $var) @@ -262,91 +262,178 @@ function pmproship_save_shipping_to_usermeta($user_id) * Show the shipping address in the profile */ function pmproship_show_extra_profile_fields( $user ) { - global $pmpro_states; - ?> -
+ global $current_user, $pmpro_states; -- | - - | -
---|---|
- | - - | -
- | - - | -
- | - - | -
- | - - | -
- | - - | -
- | - - | -
- | - - | -
- | - - | -
+ | + + | +
---|---|
+ | + + | +
+ | + + | +
+ | + + | +
+ | + + | +
+ | + + | +
+ | + + | +
+ | + + | +
+ | + + | +
' . $shipping_address . '
'; - + return $confirmation_message; } add_filter( "pmpro_confirmation_message", "pmproship_pmpro_confirmation_message", 10, 2 ); @@ -477,22 +565,22 @@ function pmproship_pmpro_confirmation_message( $confirmation_message, $pmpro_inv * Adding shipping address to confirmation email */ function pmproship_pmpro_email_body( $body, $pmpro_email ) { - + global $wpdb; - + // Init variables $user_id = null; $shipping_address = null; - + //get the user_id from the email $user = isset( $pmpro_email->data['user_email'] ) ? get_user_by( 'email', $pmpro_email->data['user_email'] ) : null; - + if ( ! empty( $user ) ) { $user_id = $user->ID; } - + if ( ! empty( $user_id ) ) { - //does the user being emailed have a shipping address? + //does the user being emailed have a shipping address? $sfirstname = get_user_meta( $user_id, "pmpro_sfirstname", true ); $slastname = get_user_meta( $user_id, "pmpro_slastname", true ); $saddress1 = get_user_meta( $user_id, "pmpro_saddress1", true ); @@ -502,7 +590,7 @@ function pmproship_pmpro_email_body( $body, $pmpro_email ) { $szipcode = get_user_meta( $user_id, "pmpro_szipcode", true ); $sphone = get_user_meta( $user_id, "pmpro_sphone", true ); $scountry = get_user_meta( $user_id, "pmpro_scountry", true ); - + $shipping_address = pmpro_formatAddress( trim( $sfirstname . ' ' . $slastname ), $saddress1, $saddress2, $scity, $sstate, $szipcode, $scountry, $sphone ); if ( ! empty( $shipping_address ) ) { @@ -514,7 +602,7 @@ function pmproship_pmpro_email_body( $body, $pmpro_email ) { } } } - + return $body; } add_filter( "pmpro_email_body", "pmproship_pmpro_email_body", 10, 2 ); @@ -588,9 +676,9 @@ function pmproship_pmpro_members_list_csv_extra_columns( $columns ) { "sphone" => "pmproship_extra_column_sphone", "scountry" => "pmproship_extra_column_scountry", ); - + $columns = array_merge( $columns, $new_columns ); - + return $columns; } @@ -719,7 +807,7 @@ function pmproship_pmpro_save_membership_level( $level_id ) { */ function pmproship_hide_shipping() { global $pmpro_level; - + $hide_shipping = get_option( 'pmpro_shipping_hidden_level_' . $pmpro_level->id, false ); if ( $hide_shipping ) { remove_action('pmpro_checkout_preheader', 'pmproship_pmpro_checkout_preheader_check_gateway', 9); @@ -728,7 +816,7 @@ function pmproship_hide_shipping() { remove_action('pmpro_checkout_preheader', 'pmproship_pmpro_checkout_preheader'); remove_action('pmpro_checkout_before_change_membership_level', 'pmproship_save_shipping_to_usermeta', 1); remove_action('pmpro_after_checkout', 'pmproship_save_shipping_to_usermeta'); - remove_action( "pmpro_checkout_before_processing", "pmproship_save_shipping_to_session", 9 ); + remove_action( "pmpro_checkout_before_processing", "pmproship_save_shipping_to_session", 9 ); } } add_filter( 'pmpro_checkout_preheader', 'pmproship_hide_shipping', 5 ); @@ -738,10 +826,10 @@ function pmproship_hide_shipping() { * NOTE: If we get around to creating a pmpro_is_checkout_page type function, use that instead */ function pmproship_load_js() { - + global $pmpro_pages; - - if ( is_admin() || is_page( $pmpro_pages['checkout'] ) ) { + + if ( is_admin() || is_page( $pmpro_pages['checkout'] ) ) { wp_enqueue_script( 'pmproship', plugins_url( 'js/pmpro-shipping.js', __FILE__ ), array( 'jquery' ), PMPRO_SHIPPING_VERSION ); } } @@ -758,7 +846,7 @@ function pmproship_plugin_row_meta( $links, $file ) { ); $links = array_merge( $links, $new_links ); } - + return $links; } add_filter( 'plugin_row_meta', 'pmproship_plugin_row_meta', 10, 2 ); diff --git a/readme.txt b/readme.txt old mode 100755 new mode 100644 index 3bbfbac..0fce436 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Paid Memberships Pro - Shipping Add On === Contributors: strangerstudios -Tags: paid memberships pro, shipping, shipping address, +Tags: paid memberships pro, shipping, shipping address, Requires at least: 4.0 -Tested up to: 5.3.2 -Stable tag: .8 +Tested up to: 5.4 +Stable tag: 1.0 Adds shipping fields to the Paid Memberships Pro checkout. @@ -11,12 +11,20 @@ Adds shipping fields to the Paid Memberships Pro checkout. Adds shipping fields to the checkout page, confirmation page, confirmation emails, member's list and edit user profile pages. +[Read the full documentation for the Shipping Add On](https://www.paidmembershipspro.com/add-ons/shipping-address-membership-checkout/) + += Official Paid Memberships Pro Add On = + +This is an official Add On for [Paid Memberships Pro](https://www.paidmembershipspro.com), the most complete member management and membership subscriptions plugin for WordPress. + == Installation == 1. Make sure you have the Paid Memberships Pro plugin installed and activated. 1. Upload the `pmpro-shipping` directory to the `/wp-content/plugins/` directory of your site. 1. Activate the plugin through the 'Plugins' menu in WordPress. +Fields will automatically be captured for all membership levels. You can remove the fields for a level on the Memberships > Settings > Edit Membership Level > "Hide Shipping Address" ssetting. + == Frequently Asked Questions == = I found a bug in the plugin. = @@ -28,6 +36,11 @@ Please post it in the GitHub issue tracker here: https://github.com/strangerstud Please visit our premium support site at http://www.paidmembershipspro.com for more documentation and our support forums. == Changelog == += 1.0 - 2020-04-30 = +* BUG FIX/ENHANCEMENT: Checking if user has a membership that includes shipping fields or is an admin before displaying fields. +* ENHANCEMENT: Added support for PMPro v2.3+ frontend profile. +* ENHANCEMENT: Setting to v1.0 to reflect the stability of the functionality and code base. + = .8 - 2020-01-06 = * ENHANCEMENT: Added phone data to confirmation message, email and Member's List area. * ENHANCEMENT: General code improvements and optimization.