shipping salesforce id on annually
This commit is contained in:
@@ -68,11 +68,36 @@ add_filter('woocommerce_add_error', 'customize_coupon_error_message', 10, 1);
|
|||||||
function customize_coupon_error_message($error) {
|
function customize_coupon_error_message($error) {
|
||||||
// Check if the error message is related to a coupon already applied
|
// Check if the error message is related to a coupon already applied
|
||||||
if (strpos($error, 'Coupon code already applied!') !== false) {
|
if (strpos($error, 'Coupon code already applied!') !== false) {
|
||||||
return ''; // Return an empty string to suppress this specific error message
|
return '';
|
||||||
}
|
}
|
||||||
return $error; // Return the original error message if it's not related to coupons
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_current_shipping_comment() {
|
||||||
|
// Get the chosen shipping methods from the cart
|
||||||
|
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
|
||||||
|
if (empty($chosen_shipping_methods)) {
|
||||||
|
return null; // No shipping methods selected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through chosen shipping methods to find their settings
|
||||||
|
foreach ($chosen_shipping_methods as $chosen_method) {
|
||||||
|
$method_parts = explode(':', $chosen_method); // Split method ID and instance ID
|
||||||
|
$shipping_method_id = $method_parts[0];
|
||||||
|
$instance_id = isset($method_parts[1]) ? $method_parts[1] : '';
|
||||||
|
|
||||||
|
// Build the option name for the instance-specific settings
|
||||||
|
$option_name = 'woocommerce_' . $shipping_method_id . '_' . $instance_id . '_settings';
|
||||||
|
$instance_settings = get_option($option_name);
|
||||||
|
|
||||||
|
// Check if `shipping_comment` exists
|
||||||
|
if (!empty($instance_settings) && isset($instance_settings['shipping_comment'])) {
|
||||||
|
return $instance_settings['shipping_comment']; // Return the first found Salesforce ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // No `shipping_comment` found
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a cart summary with accurate total calculation and full details
|
* Generates a cart summary with accurate total calculation and full details
|
||||||
@@ -157,31 +182,17 @@ function generateCartSummary($showCheckoutButton = true) {
|
|||||||
$couponDescription[] = $coupon->get_description();
|
$couponDescription[] = $coupon->get_description();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$chosen_method = WC()->session->get('chosen_shipping_methods')[0] ?? '';
|
||||||
|
error_log('Chosen Method: ' . $chosen_method);
|
||||||
|
|
||||||
|
|
||||||
$order = wc_get_order($order_id);
|
|
||||||
|
|
||||||
foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
|
$shipping_comment = get_current_shipping_comment();
|
||||||
$method_id = $shipping_item->get_method_id();
|
if ($shipping_comment) {
|
||||||
$salesforce_id = get_post_meta($order_id, '_salesforce_id_' . $method_id, true);
|
error_log('Current shipping comment (Salesforce ID): ' . $shipping_comment);
|
||||||
|
} else {
|
||||||
if (!empty($salesforce_id)) {
|
error_log('No shipping comment found for the currently applied shipping method.');
|
||||||
//echo '<p><strong>Salesforce ID:</strong> ' . esc_html($salesforce_id) . '</p>';
|
|
||||||
var_dump($salesforce_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $shipping_methods = WC()->shipping->get_shipping_methods();
|
|
||||||
//
|
|
||||||
// foreach ($shipping_methods as $shipping_method) {
|
|
||||||
// // Retrieve the settings for each shipping method instance.
|
|
||||||
// $instance_settings = get_option('woocommerce_' . $shipping_method->id . '_settings');
|
|
||||||
// $salesforce_id = $instance_settings['shipping_comment'];
|
|
||||||
// var_dump($salesforce_id);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Render with original structure and components
|
// Render with original structure and components
|
||||||
@@ -251,27 +262,9 @@ function add_custom_meta_to_order($order, $data) {
|
|||||||
// Recalculate order totals after adding fees
|
// Recalculate order totals after adding fees
|
||||||
$order->calculate_totals();
|
$order->calculate_totals();
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action('woocommerce_checkout_create_order', 'add_custom_meta_to_order', 20, 2);
|
add_action('woocommerce_checkout_create_order', 'add_custom_meta_to_order', 20, 2);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of the chosen shipping method
|
|
||||||
*/
|
|
||||||
function getShippingMethodName() {
|
|
||||||
$packages = WC()->shipping->get_packages();
|
|
||||||
|
|
||||||
if (!empty($packages)) {
|
|
||||||
// Get the chosen shipping method
|
|
||||||
$chosenMethod = WC()->session->get('chosen_shipping_methods')[0] ?? '';
|
|
||||||
|
|
||||||
// Check if the chosen shipping method exists
|
|
||||||
if (!empty($chosenMethod) && isset($packages[0]['rates'][$chosenMethod])) {
|
|
||||||
return $packages[0]['rates'][$chosenMethod]->get_label(); // Get the label (name) of the shipping method
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'Shipping'; // Default to "Standard Shipping" if no method is found
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the default title and cost for the "Shipping" flat rate method from WooCommerce settings.
|
* Retrieves the default title and cost for the "Shipping" flat rate method from WooCommerce settings.
|
||||||
*
|
*
|
||||||
@@ -297,11 +290,9 @@ function get_default_shipping_info() {
|
|||||||
$shipping_info['cost'] = $cost;
|
$shipping_info['cost'] = $cost;
|
||||||
error_log("Shipping Method Title: {$shipping_info['title']}");
|
error_log("Shipping Method Title: {$shipping_info['title']}");
|
||||||
error_log("Shipping Method Default Cost: {$shipping_info['cost']}");
|
error_log("Shipping Method Default Cost: {$shipping_info['cost']}");
|
||||||
|
|
||||||
return $shipping_info; // Exit once the method is found
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback if cost retrieval fails
|
// Fallback if cost retrieval fails
|
||||||
$shipping_info['cost'] = 'N/A';
|
$shipping_info['cost'] = 'N/A';
|
||||||
error_log("Shipping Method Cost not found using get_instance_option; using fallback 'N/A'.");
|
error_log("Shipping Method Cost not found using get_instance_option; using fallback 'N/A'.");
|
||||||
@@ -310,8 +301,6 @@ function get_default_shipping_info() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log if 'Shipping' method is not found
|
|
||||||
error_log("Shipping method 'Shipping' not found in WooCommerce settings.");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,9 +482,6 @@ function getShippingType() {
|
|||||||
return get_title_shipping_method_from_method_id($shippingMethodId);
|
return get_title_shipping_method_from_method_id($shippingMethodId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the cost of shipping
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Get the cost of shipping, providing free shipping for annual or semi-annual plans
|
* Get the cost of shipping, providing free shipping for annual or semi-annual plans
|
||||||
*
|
*
|
||||||
@@ -564,6 +550,7 @@ function get_title_shipping_method_from_method_id( $method_rate_id = '' ){
|
|||||||
$method_key_id = str_replace( ':', '_', $method_rate_id );
|
$method_key_id = str_replace( ':', '_', $method_rate_id );
|
||||||
$option_name = 'woocommerce_'.$method_key_id.'_settings';
|
$option_name = 'woocommerce_'.$method_key_id.'_settings';
|
||||||
return get_option( $option_name, true )['title'];
|
return get_option( $option_name, true )['title'];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -910,8 +897,8 @@ function apply_custom_fees_and_discounts() {
|
|||||||
$hasProfessionalInstall = isset($_SESSION["one-time"]["Professional Install"]);
|
$hasProfessionalInstall = isset($_SESSION["one-time"]["Professional Install"]);
|
||||||
$packages = WC()->shipping()->get_packages();
|
$packages = WC()->shipping()->get_packages();
|
||||||
if (!empty($packages) && !empty($packages[0]['rates'])) {
|
if (!empty($packages) && !empty($packages[0]['rates'])) {
|
||||||
if (($ratePlan === 'Annually' || $ratePlan === 'Semi-Annually' || $isAarpMember || $hasProfessionalInstall) && isset($packages[0]['rates']['free_shipping:4'])) {
|
if (($ratePlan === 'Annually' || $ratePlan === 'Semi-Annually' || $isAarpMember || $hasProfessionalInstall) && isset($packages[0]['rates']['free_shipping:1'])) {
|
||||||
WC()->session->set('chosen_shipping_methods', ['free_shipping:4']);
|
WC()->session->set('chosen_shipping_methods', ['free_shipping:1']);
|
||||||
} elseif ($ratePlan === 'Monthly' && isset($packages[0]['rates']['flat_rate:2'])) {
|
} elseif ($ratePlan === 'Monthly' && isset($packages[0]['rates']['flat_rate:2'])) {
|
||||||
WC()->session->set('chosen_shipping_methods', ['flat_rate:2']);
|
WC()->session->set('chosen_shipping_methods', ['flat_rate:2']);
|
||||||
}
|
}
|
||||||
@@ -1123,6 +1110,7 @@ function getProductAccessories($product_id) {
|
|||||||
* Creates the payload for the order to send to Salesforce.
|
* Creates the payload for the order to send to Salesforce.
|
||||||
*/
|
*/
|
||||||
function createOrderRequest($order) {
|
function createOrderRequest($order) {
|
||||||
|
$shipping_comment = get_current_shipping_comment();
|
||||||
// Retrieve card type from order meta
|
// Retrieve card type from order meta
|
||||||
$card_type = get_post_meta($order->get_id(), '_card_type', true);
|
$card_type = get_post_meta($order->get_id(), '_card_type', true);
|
||||||
|
|
||||||
@@ -1195,7 +1183,7 @@ function createOrderRequest($order) {
|
|||||||
"CustomField3" => "",
|
"CustomField3" => "",
|
||||||
"CustomField4" => "",
|
"CustomField4" => "",
|
||||||
"MarketingCampaign" => "ecom campaign",
|
"MarketingCampaign" => "ecom campaign",
|
||||||
"ShippingID" => "a4t3s000000pYVVAA2",
|
"ShippingID" => $shipping_comment,
|
||||||
"PaymentInformation" => [
|
"PaymentInformation" => [
|
||||||
"PaymentType" => $payment_type,
|
"PaymentType" => $payment_type,
|
||||||
"CardholderName" => $billing['first_name'] . ' ' . $billing['last_name'],
|
"CardholderName" => $billing['first_name'] . ' ' . $billing['last_name'],
|
||||||
|
|||||||
Reference in New Issue
Block a user