/* ======================================================= البداية: كود الفورم (النسخة النهائية المصححة) ======================================================= */ // 1. تعريف الكود المختصر add_shortcode('pro_cod_form', 'render_cod_form_final'); function render_cod_form_final() { global $product; // إصلاح مشكلة عدم ظهور المنتج في ShopBuilder if ( ! is_product() || ! is_a($product, 'WC_Product') ) { $product_id = get_the_ID(); if($product_id) { $product = wc_get_product($product_id); } } if( ! $product ) return ''; ob_start(); $product_id = $product->get_id(); $single_price = floatval( $product->get_price() ); if( $single_price <= 0 ) $single_price = floatval( $product->get_regular_price() ); $pack1_price = number_format( $single_price, 0, '.', '' ); $pack2_price = number_format( max(0, $single_price * 2 - 50), 0, '.', '' ); $nonce_field = wp_create_nonce('quick_cod_order_nonce'); // --- جلب الخيارات من السمات (Attributes) --- $default_options = array("العربية - الفرنسية", "العربية - الإنجليزية", "العربية - الإسبانية"); // البحث عن سمة باسم 'Options' أو 'options' $custom_options_str = $product->get_attribute('Options'); if( empty($custom_options_str) ){ $custom_options_str = $product->get_attribute('options'); } if( ! empty($custom_options_str) ){ // تحويل النص إلى مصفوفة (الفاصل هو |) $final_options = array_map('trim', explode('|', $custom_options_str)); } else { $final_options = $default_options; } $options_html = ''; foreach($final_options as $opt){ $options_html .= ''; } // ---------------------------------------- ?>