// ============================= // SH-SARTORE ESCROW CORE LOGIC // ============================= // 1. Set Custom Email Sender add_filter('wp_mail_from', fn() => 'admin@sh-sartore.com'); add_filter('wp_mail_from_name', fn() => 'ShโSartore Escrow System'); // 2. Load CSS & JS Assets function enqueue_escrow_assets() { wp_enqueue_style('escrow-style', get_template_directory_uri() . '/css/dark-glass-theme.css'); if (is_page_template('page-templates/escrow-form.php')) { wp_enqueue_script('escrow-ajax', get_template_directory_uri() . '/js/escrow-ajax.js', ['jquery'], null, true); wp_localize_script('escrow-ajax', 'escrowAjax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'escrow_nonce' => wp_create_nonce('escrow_ajax_nonce') ]); } if (is_page_template('page-templates/complete-escrow.php')) { wp_enqueue_script('wallet-status', get_template_directory_uri() . '/js/wallet-status.js', ['jquery'], null, true); wp_localize_script('wallet-status', 'walletAjax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'escrow_nonce' => wp_create_nonce('escrow_ajax_nonce') ]); } } add_action('wp_enqueue_scripts', 'enqueue_escrow_assets'); // 3. Register Custom Post Types add_action('init', function () { register_post_type('escrow_deal', [ 'labels' => ['name' => 'Escrow Deals'], 'public' => true, 'show_in_menu' => true, 'supports' => ['title'] ]); register_post_type('escrow_review', [ 'labels' => ['name' => 'Escrow Reviews'], 'public' => false, 'show_ui' => true, 'menu_icon' => 'dashicons-format-status', 'supports' => ['title', 'editor', 'custom-fields'] ]); register_post_type('escrow_dispute', [ 'labels' => ['name' => 'Escrow Disputes'], 'public' => false, 'show_ui' => true, 'menu_icon' => 'dashicons-warning', 'supports' => ['title', 'editor', 'custom-fields'] ]); }); // 4. Submit Escrow via AJAX (with debug + email + redirect) add_action('wp_ajax_submit_escrow_ajax', 'submit_escrow_ajax'); add_action('wp_ajax_nopriv_submit_escrow_ajax', 'submit_escrow_ajax'); function submit_escrow_ajax() { check_ajax_referer('escrow_ajax_nonce', 'escrow_nonce'); $debug = []; $deal_id = wp_insert_post([ 'post_title' => sanitize_text_field($_POST['deal_title']), 'post_type' => 'escrow_deal', 'post_status'=> 'publish', ]); if (!$deal_id) { wp_send_json_error(['message' => 'โ Failed to create deal.']); } $debug[] = "โ Deal created with ID: $deal_id"; $fields = [ 'deal_type', 'currency', 'fee_payer', 'due_date', 'inspection_period', 'item_name', 'price', 'description', 'shipping', 'buyer_phone' ]; foreach ($fields as $field) { $value = sanitize_text_field($_POST[$field] ?? ''); update_post_meta($deal_id, $field, $value); $debug[] = "๐ Meta saved: $field = $value"; } $buyer_email = sanitize_email($_POST['buyer_email']); $seller_email = sanitize_email($_POST['seller_email']); $price = floatval($_POST['price']); $fee = round($price * 0.05, 2); $total = $price + $fee; update_post_meta($deal_id, 'buyer_email', $buyer_email); update_post_meta($deal_id, 'seller_email', $seller_email); update_post_meta($deal_id, 'escrow_fee', $fee); update_post_meta($deal_id, 'buyer_pays', $total); update_post_meta($deal_id, 'seller_receives', $price); update_post_meta($deal_id, 'escrow_status', 'pending'); $debug[] = "๐ฐ Amounts stored: price=$price fee=$fee total=$total"; $link = esc_url(site_url("/complete-escrow/?id=$deal_id")); $subject = '๐ New Escrow Deal Submitted'; $headers = ['Content-Type: text/html; charset=UTF-8']; $body = "
Transaction: {$_POST['deal_title']}
Item: {$_POST['item_name']}
Currency: {$_POST['currency']}
Amount: \${$price} + Fee \${$fee} = \${$total}
Buyer: $buyer_email
Seller: $seller_email
๐ Complete or View Escrow Deal
Powered by ShโSartore Escrow โ Visit Website