public function save_post() { if ($this->is_updating_a_translatable_post_with_acf_fields()) { $this->reg_ext_patterns = array(); $fields = get_field_objects($_POST['post_ID']); if ($fields && is_array($fields)) { $this->update_custom_fields_settings($fields); $this->update_post_meta_settings(); } } }
function wp_post_revision_fields($return) { //globals global $post, $pagenow; // validate $allowed = false; // Normal revisions page if ($pagenow == 'revision.php') { $allowed = true; } // WP 3.6 AJAX revision if ($pagenow == 'admin-ajax.php' && isset($_POST['action']) && $_POST['action'] == 'get-revision-diffs') { $allowed = true; } // bail if (!$allowed) { return $return; } // vars $post_id = 0; // determin $post_id if (isset($_POST['post_id'])) { $post_id = $_POST['post_id']; } elseif (isset($post->ID)) { $post_id = $post->ID; } else { return $return; } // get field objects $fields = get_field_objects($post_id, array('format_value' => false)); if ($fields) { foreach ($fields as $field) { // dud field? if (!$field || !isset($field['name']) || !$field['name']) { continue; } // Add field key / label $return[$field['name']] = $field['label']; // load value add_filter('_wp_post_revision_field_' . $field['name'], array($this, 'wp_post_revision_field'), 10, 4); // WP 3.5: left vs right // Add a value of the revision ID (as there is no way to determin this within the '_wp_post_revision_field_' filter!) if (isset($_GET['action'], $_GET['left'], $_GET['right']) && $_GET['action'] == 'diff') { global $left_revision, $right_revision; $left_revision->{$field}['name'] = 'revision_id=' . $_GET['left']; $right_revision->{$field}['name'] = 'revision_id=' . $_GET['right']; } } } return $return; }
public function __construct($id = null) { if (is_int($id)) { $new_fields = array(); $fields = get_field_objects($id); if (is_array($fields)) { foreach ($fields as $k => $field) { $new_fields[$k] = $field['key']; } if (!empty($new_fields)) { foreach ($new_fields as $field_id => $key) { $this->{$field_id} = get_field($key, $id); } } } } }
function get_fonts_to_enqueue() { if (is_singular()) { global $post; $post_fields = get_field_objects($post->ID); } $post_fields = empty($post_fields) ? array() : $post_fields; $option_fields = get_field_objects('options'); $option_fields = empty($option_fields) ? array() : $option_fields; $fields = array_merge($post_fields, $option_fields); $font_fields = array(); foreach ($fields as $field) { if (!empty($field['type']) && 'google_font_selector' == $field['type'] && !empty($field['value'])) { $font_fields[] = $field['value']; } } return $font_fields; }
/** * Gets all of the custom text fields * * @package pp * @subpackage boilerplate-theme * * @param int $id Specific ID of post to look up fields of * @return array Array of custom fields * */ function pp_get_custom_fields($id = false) { // Get the post ID if (!$id) { $id = get_the_ID(); } // Get custom fields $custom = get_post_custom($id); // Grab ACF fields $acf = false; if (function_exists('get_field_objects')) { $acf = get_field_objects($id); } // We're going to filter a bit and store the result here $custom_fields = array(); // Loop through and exclude underscore prefixed fields and ACF fields foreach ($custom as $key => $value) { // Exclude underscore prefixed keys if (substr($key, 0, 1) == '_') { continue; } // Skip acf fields $split_nesteds = preg_split('(_[0-9]+_)', $key); if ($acf && isset($acf[$split_nesteds[0]])) { continue; } $custom_fields[$key] = $value; } // Loop through ACF fields too if ($acf) { foreach ($acf as $key => $value) { // Exclude underscore prefixed keys if (substr($key, 0, 1) == '_') { continue; } // Only doing text fields if ($value['type'] == 'text') { $custom_fields[$value['label']][] = get_field($value['name']); } } } return $custom_fields; }
/** * Событие вызываемое при сохранении / изменении поста * @param $postId */ function onSavePost($postId) { $fields = get_field_objects($postId); if (isset($fields['detail_image']) && isset($fields['detail_image']['key']) && !empty($fields['detail_image']['key']) && isset($fields['preview_image']) && isset($fields['preview_image']['key']) && !empty($fields['preview_image']['key']) && isset($_POST['fields'][$fields['detail_image']['key']]) && !empty($_POST['fields'][$fields['detail_image']['key']]) && isset($_POST['fields'][$fields['preview_image']['key']])) { $detailImageId = $_POST['fields'][$fields['detail_image']['key']]; $previewImageId =& $_POST['fields'][$fields['preview_image']['key']]; $detailImageData = wp_get_attachment_image_src($detailImageId, 'full'); if (isset($detailImageData[0]) && !empty($detailImageData[0])) { $detailImageUrl = $detailImageData[0]; $detailImagePath = $_SERVER['DOCUMENT_ROOT'] . str_replace(get_site_url(), '', $detailImageUrl); $image = wp_get_image_editor($detailImagePath); if (!is_wp_error($image)) { $image->resize(300, 230, true); $image->save($detailImagePath); } $previewImageId = $detailImageId; } } //var_dump($postId, $fields, $_POST); die; }
function ie_get_form($form, $id) { //get form based on app taxonomy //to do to reduce duplicate $answers = get_posts(array('post_type' => $form, 'numberposts' => -1, 'tax_query' => array(array('taxonomy' => 'app_name', 'field' => 'slug', 'terms' => $id)))); if ($answers) { $fields = get_field_objects($answers[0]->ID); //echo '<pre>'; print_r($fields); echo '</pre>'; $out = array(); $out[] = '<table width="100%">'; if ($fields) { foreach ($fields as $field_name => $field) { $out[] = '<tr>'; $out[] = '<td><b>' . $field['label'] . '</b></td>'; $find_it = $field['choices']; if ($find_it) { foreach ($find_it as $find => $key) { //echo $key; //echo '</br>'; if ($find == $field['value']) { $out[] = '<td>' . $key . '</td>'; } } } else { $out[] = '<td>' . $field['value'] . '</td>'; } $out[] = '</tr>'; } } $out[] = '</table>'; } else { $out[] = 'No form filled in for this app'; } //echo '<pre>';print_r($fields);echo '</pre>'; wp_reset_postdata(); echo implode($out); }
public static function validate_hotel_data($data) { $field_data = array(); $fields = get_field_objects($data['hotel_id']); if (!empty($fields)) { foreach ($fields as $k => $field) { $field_data[$k] = $field['type']; } } if (!empty($data)) { foreach ($data as $k => $d) { if ($field_data[$k] != null) { } else { } } } return true; }
/** * Get all the fields for the target object. * * @param int $target_id The id of the target object. * @return array */ private static function get_all_fields($target_id = 0) { $data = []; $field_objs = get_field_objects($target_id); if ($field_objs) { foreach ($field_objs as $field_name => $field_obj) { $value = self::get_single_field($target_id, $field_obj); $group_slug = self::get_group_slug($field_obj['parent']); if ($group_slug) { $data[$group_slug][$field_name] = $value; } else { $data[$field_name] = $value; } } } return $data; }
function count_single_form_answered($type, $app_id) { // first check if form exists for app id $posts = get_posts(array('post_type' => $type, 'tax_query' => array(array('taxonomy' => 'app_name', 'field' => 'term_id', 'terms' => $app_id)))); //now count questions completed per form $fields = get_field_objects($posts[0]->ID); if ($posts != null) { // $i represents filled in value $i = 0; if ($fields) { foreach ($fields as $field) { if ($field['value'] != null && $field['value'] != "SELECT ANSWER") { // do counting here $i++; } } } } //return total answered for form return $i; }
$projecte = new TimberPost($projecte->ID); $content_title = 'Col·laboreu en el projecte ' . $projecte->post_title; $projecte->project_requirements = apply_filters('the_content', $projecte->project_requirements); $projecte->lectures_recomanades = apply_filters('the_content', $projecte->lectures_recomanades); $context_filterer = new SC_ContextFilterer(); $context = $context_filterer->get_filtered_context(array('title' => $content_title . '| Softcatalà')); $context['projecte'] = $projecte; $context['steps'] = $projecte->get_field('steps'); $templates = array('plantilla-steps-single.twig'); $args = array('meta_query' => array(get_meta_query_value('projectes', $projecte->ID, 'like', ''))); $context['membres'] = get_users($args); } else { $post = Timber::get_post(); $profile = $post->get_field('perfil'); $profile_label = get_field_object('perfil', $post->ID); $all_acf_data = get_field_objects($post->ID); $content_title = 'Col·laboreu amb nosaltres: ' . $profile_label['choices'][$profile]; if (false === $profile || empty($profile)) { wp_redirect('/col·laboreu/', 302); } $project_args = array('tax_query' => array(array('taxonomy' => 'ajuda-projecte', 'field' => 'slug', 'terms' => $profile), array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN'))); $projects = $sc_types['projectes']->get_sorted_projects($project_args); $context = Timber::get_context(); $context['projectes'] = $projects; $context['steps'] = $post->get_field('steps'); } $post = new TimberPost(); $context['post'] = $post; $context['content_title'] = $content_title; $context['links'] = $post->get_field('link'); $context['sidebar_top'] = Timber::get_widgets('sidebar_top');
?> </ul> </header> <div class="grid-loader"><i class="icon-spinner icon-spin"></i></div> <?php $args = array('post_type' => 'wedding-styles', 'order' => 'asc', 'orderby' => 'title', 'taxonomy' => 'wedding-styles', 'post_status' => 'publish', 'posts_per_page' => -1); $loop = new WP_Query($args); ?> <div id="wpex-grid-wrap2" class="grid"> <div class="gutter-sizer"></div> <?php while ($loop->have_posts()) { $loop->the_post(); ?> <?php $fields = get_field_objects($post->ID); $allowed = array("logo_1", "logo_2", "logo_3", "logo_4"); $fields_xx = array_intersect_key($fields, array_flip($allowed)); if ($fields_xx) { foreach ($fields_xx as $field_name => $field) { ?> <article <?php post_class('grid-item ' . $post->post_name . ' item container'); ?> > <?php wpex_hook_entry_top(); ?> <a href="<?php the_permalink(); ?>
/** * Retrieve attachments in the fields of type file of the post * * @param array $attachments * @param string $post * */ public function filter_get_post_attachments($attachments, $post_id) { if (!WPSOLR_Metabox::get_metabox_is_do_index_acf_field_files($post_id)) { // Do nothing return $attachments; } // Get post ACF field objects $fields = get_field_objects($post_id); if ($fields) { foreach ($fields as $field_name => $field) { // Retrieve the post_id of the file if (!empty($field['value']) && self::ACF_TYPE_FILE === $field['type']) { switch ($field['save_format']) { case self::ACF_TYPE_FILE_ID: array_push($attachments, array('post_id' => $field['value'])); break; case self::ACF_TYPE_FILE_OBJECT: array_push($attachments, array('post_id' => $field['value']['id'])); break; case self::ACF_TYPE_FILE_URL: array_push($attachments, array('url' => $field['value'])); break; default: // Do nothing break; } } } } return $attachments; }
function get_fields($post_id = false) { $fields = get_field_objects($post_id); if (is_array($fields)) { foreach ($fields as $k => $field) { $fields[$k] = $field['value']; } } return $fields; }
public function get_meta($id, $data = array()) { $meta = get_field_objects($id); return $meta; }
function acf_cf_email_template() { global $post; $post_id = $_GET['acf-cf-email']; $post = get_post($post_id); setup_postdata($post); if (empty($_GET['template'])) { echo '<h3 style="text-align: center;">' . get_the_title($post->ID) . '</h3>'; $fields = get_field_objects($post_id); $message = '<table class="table table-striped" style="width: 100%; font-family: helvetica,arial;">'; foreach ($fields as $field) { if (!empty($field['value'])) { $message .= '<tr>'; $message .= '<td style="padding: 5px; width: 20%; text-align: right;" align="right" valign="top"><strong>' . $field['label'] . ': </strong></td>'; $value = $field['value']; $message .= '<td style="padding: 5px;" align="left" valign="top">'; $message .= acf_cf_format_message($field['value'], $field['type'], $field, $post_id); $message .= '</td>'; $message .= '</tr>'; } } $message .= '</table>'; echo $message; } else { $template = $_GET['template']; $template = get_template_directory() . '/acf-cf-templates/acf-cf-' . $template . '.php'; require_once $template; } die; }
/** * * Displays attached additional meta fields * @since 0.0.1 * */ public function show_attached_fields($content) { $fields = get_field_objects($this->ID); if ($fields) { // create a string to hold the output $output = ''; foreach ($fields as $field_name => $field) { //print_r($field); //echo '<br><br>'; // setup defaults for filters $display_info = array("before_field" => '<div>', "after_field" => '</div>', "show_label" => true, "label" => $field['label'], "before_label" => '<h3 class="df_field_label">', "after_label" => '</h3>', "main" => $field['value']); // allow filtering if (has_filter('df_field_display')) { $display_info = apply_filters('df_field_display', $display_info, $field); } $output .= $display_info['before_field']; if ($display_info['show_label']) { $output .= $display_info['before_label'] . $display_info['label'] . $display_info['after_label']; } /* // some fields need to have a custom display $custom_class = 'df_field_' . $field['type']; if (class_exists($custom_class)){ $custom_class::show_field($this->ID, $field_name); } else { echo $display_info['main']; } */ $output .= $display_info['main']; $output .= $display_info['after_field']; } // add the output to the content $content .= $output; } return $content; }
/** * @param $post * @return array * * returns the ACF fields associated with a given post * called by the 'add_acf_fields_to_content' callback * */ private function acf_fields_for_post_at_depth($post, $depth) { $acf_fields = get_fields($post->ID); if (!$acf_fields) { return []; } // field groups that have been associated with this post $post_field_groups = array_filter(get_field_objects($post->ID), function ($f) { return $f['value']; }); $field_value = array_filter($acf_fields, function ($f) { return $f !== false; }); // iterate over the acf groups $acf_data = array_map(function ($group) use($field_value, $post, $post_field_groups, $depth) { // the response group is the container for the individual fields $response_group = array('title' => $group['title']); $acf_fields = $this->get_acf_fields_in_group($group); $post_has_group = array_filter($post_field_groups, function ($field_group) use($group) { return $field_group['field_group'] == $group['id']; }); if (!$post_has_group) { return null; } // now we have a group and its fields - get the fields that correspond to this post (from the $custom_fields array) $response_group['fields'] = array_map(function ($acf_field) use($field_value, $depth) { $acf_field = apply_filters('acf/load_field', $acf_field, $acf_field['key']); if (array_key_exists($acf_field['name'], $field_value)) { $response_value = $this->process_field($acf_field, $field_value, $depth); } else { // we still include the field in the response so we can test `if !somefield.empty?` rather than `if response.responds_to?(:somefield) && !somefield.empty?` $response_value = array('name' => $acf_field['name'], 'label' => $acf_field['label'], 'value' => ""); } return $response_value; }, $acf_fields); return $response_group; }, apply_filters('acf/get_field_groups', array())); $fieldsets = array_filter($acf_data); return array_values($fieldsets); }
function watcher_acf_save_post($post_id) { if ('options' == $post_id) { $fields = get_field_objects('options'); // load from post if ($fields) { $var = $var1 = ''; foreach ($fields as $key => $value) { $finfo = get_field_object($key, $post_id, array("load_value" => true)); if (is_array($finfo)) { if (substr($finfo['name'], 0, 2) == 's_') { $type = $finfo['type']; switch ($type) { case 'repeater': // $var .= chr(13); if (empty($finfo['value'])) { $var .= '$' . $finfo['name'] . ': null;' . chr(13); } else { $i = 1; $pvar = '$' . $finfo['name'] . ': (' . count($finfo['value']) . '), ('; $prx = '$' . $finfo['name'] . '_'; foreach ($finfo['value'] as $row) { // Uncomment below line to create an id for each skin: // $skin_name = $finfo['name'] . '_' . $i; $pvar .= $prx . $i . ', '; $rvar = $prx . $i++ . ': '; // Uncomment below line to create an id for each skin: // $rvar .= $skin_name . ', '; foreach ($row as $key => $val) { if (empty($val)) { $val = 'null'; } // If name of field have 'ns_' prefix this field don't display in sass settings. if (substr($key, 0, 3) != 'ns_') { if ($key == 'skin_name') { $rvar .= sanitize_title($val) . ', '; } else { if (substr($key, 0, 3) == 'bg_') { // $rvar .= $val . ', '; // echo '<pre>'; // print_r(background_field_validate($rvar, $val, $key)); // echo '</pre>'; $rvar = background_field_validate($rvar, $val, $key, 'repeater'); } else { $rvar .= $val . ', '; } } } } if (substr($rvar, -2) == ', ') { $rvar = substr($rvar, 0, -2); } $rvar .= ';' . chr(13); $var1 .= $rvar; } if (substr($pvar, -2) == ', ') { $pvar = substr($pvar, 0, -2); $pvar .= ');' . chr(13); } $var1 .= $pvar; } // $var .= chr(13); break; case 'text': if (is_null($finfo['value']) || $finfo['value'] == '') { $var .= '$' . $finfo['name'] . ': null;' . chr(13); } else { $var .= "\$" . $finfo['name'] . ": '" . $finfo['value'] . "';" . chr(13); } break; case 'background': $var = background_field_validate($var, $finfo['value'], $finfo['name'], 'background'); break; case 'true_false': if ($finfo['value'] == 1) { $var .= '$' . $finfo['name'] . ': true;' . chr(13); } else { $var .= '$' . $finfo['name'] . ': false;' . chr(13); } break; case 'typography': $var = typography_field_validate($var, $finfo['value'], $finfo['name']); break; default: if (is_null($finfo['value']) || $finfo['value'] == '') { $var .= '$' . $finfo['name'] . ': null;' . chr(13); } else { if (is_array($finfo['value'])) { $var .= '$' . $finfo['name'] . ': '; foreach ($finfo['value'] as $key => $value) { if (is_null($value)) { $value = 'null'; } $var .= '(' . $key . ', ' . $value . '), '; } $var = rtrim($var, ', '); $var .= ';' . chr(13); } else { $var .= '$' . $finfo['name'] . ': ' . $finfo['value'] . ';' . chr(13); } } } } } } } if (isset($var1)) { $var .= $var1; } $sw = new sass_watcher(); $conf = $sw->getdata(); $scss_forlder = get_template_directory() . '/' . $conf['sassdir']; $scss_filename = $scss_forlder . '/' . $conf['sassfile']; $scss_style = get_template_directory() . '/' . $conf['cssdir']; $varfilename = $scss_forlder . '/' . $conf['varfilename']; file_put_contents($varfilename, $var); $sw->compile($scss_forlder, $scss_filename, $scss_style); } }
/** * Get ACF field data based on revision * @param Object $revisions WP Post Object * @param int $post_id original post id * @return array array of revisions */ public function get_acf_revisions($revisions, $post_id) { if (!empty($revisions)) { foreach ($revisions as $index => $revision) { $revisions[$index]->acf_fields = get_field_objects($revision->ID); } } return $revisions; }
<?php /* This is the custom post type post template. If you edit the post type name, you've got to change the name of this template to reflect that name change. i.e. if your custom post type is called register_post_type( 'bookmarks', then your single template should be single-bookmarks.php */ ?> <?php get_header(); ?> <?php $context = array(); $post = new TimberPost(); $context = Timber::get_context(); $context['post'] = $post; $context["acf"] = get_field_objects($data['post']->ID); Timber::render('single-blog.twig', $context); // print_r($context); ?> <?php get_footer();
</div> <div class="slide"><?php echo jdo_get_history_slide('histoire/histoire-1992'); ?> </div> <div class="slide"><?php echo jdo_get_history_slide('histoire/histoire-aujourdhui'); ?> </div> </div> </div> <?php // ANNONCES $annonces = get_page_by_path('annonces'); $fields = get_field_objects($annonces->ID); ?> <div class="row small-12 columns" id="annonces"> <h2 class="title title-margin"><?php echo apply_filters('the_title', $annonces->post_title); ?> </h2> <div class="row small-12 columns" data-equalizer> <div class="small-6 columns block-margin" data-equalizer-watch> <div> <h3><span class="icon icon_adjust-horiz"></span>Fiche téchnique</h3> <div class="table table-50 table-padding"> <div> <div><strong><?php
private function get_acf_fields() { if (function_exists('get_field_objects')) { $this->acfs = get_field_objects($this->parent_id); } }
public function sync() { global $wp; global $wpdb; set_time_limit(0); @ini_set('display_errors', '1'); @ini_set('zlib.output_compression', 'Off'); @ini_set('output_buffering', 'Off'); @ini_set('output_handler', ''); while (ob_get_level() > 1) { @ob_end_clean(); } if (ob_get_level() > 0) { @ob_clean(); } if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { $this->sendHttpHeaders('500 Config Error', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode(array('ack' => 'failed', 'message' => 'WooCommerce Deactivated')); exit; } $type = $wp->query_vars['codisto-sync-route']; if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') { if ($type == 'test' || $type == 'sync' && preg_match('/\\/sync\\/testHash\\?/', $_SERVER['REQUEST_URI'])) { if (!$this->check_hash()) { exit; } $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode(array('ack' => 'ok')); } else { if ($type === 'settings') { if (!$this->check_hash()) { exit; } $logo_url = get_header_image(); if (function_exists('site_logo')) { $logo = site_logo()->logo; $logo_id = get_theme_mod('custom_logo'); $logo_id = $logo_id ? $logo_id : $logo['id']; if ($logo_id) { $logo_url = wp_get_attachment_image_src($logo_id, 'full'); $logo_url = $logo_url[0]; } } $currency = get_option('woocommerce_currency'); $dimension_unit = get_option('woocommerce_dimension_unit'); $weight_unit = get_option('woocommerce_weight_unit'); $default_location = explode(':', get_option('woocommerce_default_country')); $country_code = isset($default_location[0]) ? $default_location[0] : ''; $state_code = isset($default_location[1]) ? $default_location[1] : ''; $response = array('ack' => 'ok', 'logo' => $logo_url, 'currency' => $currency, 'dimension_unit' => $dimension_unit, 'weight_unit' => $weight_unit, 'country_code' => $country_code, 'state_code' => $state_code); $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } else { if ($type === 'tax') { if (!$this->check_hash()) { exit; } $tax_enabled = true; if (function_exists('wc_tax_enabled')) { $tax_enabled = wc_tax_enabled(); } else { $tax_enabled = get_option('woocommerce_calc_taxes') === 'yes'; } if ($tax_enabled) { $rates = $wpdb->get_results("SELECT tax_rate_country AS country, tax_rate_state AS state, tax_rate AS rate, tax_rate_name AS name, tax_rate_class AS class, tax_rate_order AS sequence, tax_rate_priority AS priority FROM `{$wpdb->prefix}woocommerce_tax_rates` ORDER BY tax_rate_order"); } else { $rates = array(); } $response = array('ack' => 'ok', 'tax_rates' => $rates); $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } else { if ($type === 'products') { if (!$this->check_hash()) { exit; } $page = isset($_GET['page']) ? (int) $_GET['page'] : 0; $count = isset($_GET['count']) ? (int) $_GET['count'] : 0; $product_ids = isset($_GET['product_ids']) ? json_decode(wp_unslash($_GET['product_ids'])) : null; if (!is_null($product_ids)) { if (!is_array($product_ids)) { $product_ids = array($product_ids); } $product_ids = array_filter($product_ids, create_function('$v', 'return is_numeric($v);')); if (!isset($_GET['count'])) { $count = count($product_ids); } } $products = $wpdb->get_results($wpdb->prepare("SELECT id AS id " . "FROM `{$wpdb->prefix}posts` AS P " . "WHERE post_type = 'product' " . "\t\tAND post_status IN ('publish', 'future', 'pending', 'private') " . "\t" . (is_array($product_ids) ? 'AND id IN (' . implode(',', $product_ids) . ')' : '') . "" . "ORDER BY ID LIMIT %d, %d", $page * $count, $count)); if (!is_array($product_ids) && $page === 0) { $total_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}posts` WHERE post_type = 'product' AND post_status IN ('publish', 'future', 'pending', 'private')"); } $acf_installed = function_exists('acf'); foreach ($products as $product) { $wc_product = $this->get_product($product->id); $categoryproduct = $wc_product->get_categories(); $product->sku = $wc_product->get_sku(); $product->name = html_entity_decode(apply_filters('woocommerce_product_title', $wc_product->post->post_title, $wc_product), ENT_COMPAT | ENT_HTML401, 'UTF-8'); $product->enabled = $wc_product->is_purchasable() && ($wc_product->managing_stock() || $wc_product->is_in_stock()); $product->price = $wc_product->get_price_excluding_tax(); $product->listprice = floatval($wc_product->get_regular_price()); $product->is_taxable = $wc_product->is_taxable(); $product->tax_class = $wc_product->get_tax_class(); $product->stock_control = $wc_product->managing_stock(); $product->stock_level = $wc_product->get_stock_quantity(); if (method_exists($wc_product, 'get_type')) { $product->type = $wc_product->get_type(); } else { $product->type = $wc_product->product_type; } $product->description = apply_filters('the_content', $wc_product->post->post_content); $product->short_description = apply_filters('the_content', $wc_product->post->post_excerpt); if (method_exists($wc_product, 'get_width')) { $product->width = $wc_product->get_width(); if (!is_numeric($product->width)) { unset($product->width); } $product->height = $wc_product->get_height(); if (!is_numeric($product->height)) { unset($product->height); } $product->length = $wc_product->get_length(); if (!is_numeric($product->length)) { unset($product->length); } } else { $product->length = $wc_product->length; $product->width = $wc_product->width; $product->height = $wc_product->height; } $product->weight = $wc_product->get_weight(); if (!is_numeric($product->weight)) { unset($product->weight); } if ($product->is_taxable && 'yes' === get_option('woocommerce_prices_include_tax')) { $tax_rates = WC_Tax::get_shop_base_rate($product->tax_class); $taxes = WC_Tax::calc_tax($product->listprice, $tax_rates, true); $product->listprice = $product->listprice - array_sum($taxes); } if ($product->type == 'variable') { $product->skus = array(); foreach ($wc_product->get_children() as $child_id) { $child_product = $wc_product->get_child($child_id); $img = wp_get_attachment_image_src($child_product->get_image_id(), 'full'); $img = $img[0]; $child_product_data = array('id' => $child_id, 'sku' => $child_product->get_sku(), 'enabled' => $wc_product->is_purchasable() && ($wc_product->managing_stock() || $wc_product->is_in_stock()), 'price' => $child_product->get_price_excluding_tax(), 'listprice' => $child_product->get_regular_price(), 'is_taxable' => $child_product->is_taxable(), 'tax_class' => $child_product->get_tax_class(), 'stock_control' => $child_product->managing_stock(), 'stock_level' => $child_product->get_stock_quantity(), 'images' => array(array('source' => $img, 'sequence' => 0))); $attributes = array(); $termsmap = array(); $names = array(); foreach ($child_product->get_variation_attributes() as $name => $value) { $name = preg_replace('/(pa_)?attribute_/', '', $name); if (!isset($names[$name])) { $names[$name] = true; $terms = get_terms(array('taxonomy' => $name)); if ($terms) { foreach ($terms as $term) { $termsmap[$term->slug] = $term->name; } } } if ($value && (gettype($value) == 'string' || gettype($value) == 'integer')) { if (array_key_exists($value, $termsmap)) { $newvalue = $termsmap[$value]; } else { $newvalue = $value; } } else { $newvalue = ''; } $name = wc_attribute_label($name, $child_product); $attributes[] = array('name' => $name, 'value' => $newvalue, 'slug' => $value); } foreach (get_post_custom_keys($child_product->variation_id) as $attribute) { if (!(in_array($attribute, array('_sku', '_weight', '_length', '_width', '_height', '_thumbnail_id', '_virtual', '_downloadable', '_regular_price', '_sale_price', '_sale_price_dates_from', '_sale_price_dates_to', '_price', '_download_limit', '_download_expiry', '_file_paths', '_manage_stock', '_stock_status', '_downloadable_files', '_variation_description', '_tax_class', '_tax_status', '_stock', '_default_attributes', '_product_attributes', '_file_path', '_backorders')) || substr($attribute, 0, 4) === '_wp_' || substr($attribute, 0, 13) === 'attribute_pa_')) { $value = get_post_meta($child_product->variation_id, $attribute, false); if (is_array($value)) { if (count($value) === 1) { $value = $value[0]; } else { $value = implode(',', $value); } } $attributes[] = array('name' => $attribute, 'value' => $value, 'custom' => true); } } $child_product_data['attributes'] = $attributes; $product->skus[] = $child_product_data; } $attrs = array(); foreach ($wc_product->get_variation_attributes() as $name => $value) { $name = preg_replace('/(pa_)?attribute_/', '', $name); if (!isset($names[$name])) { $names[$name] = true; $terms = get_terms(array('taxonomy' => $name)); if ($terms) { foreach ($terms as $term) { $termsmap[$term->slug] = $term->name; } } } if ($value && (gettype($value) == 'string' || gettype($value) == 'integer')) { if (array_key_exists($value, $termsmap)) { $newvalue = $termsmap[$value]; } else { $newvalue = $value; } } else { $newvalue = ''; } $name = wc_attribute_label($name, $child_product); $attrs[] = array('name' => $name, 'value' => $newvalue, 'slug' => $value); } $product->options = $attrs; } else { if ($product->type == 'grouped') { $product->skus = array(); foreach ($wc_product->get_children() as $child_id) { $child_product = $wc_product->get_child($child_id); $child_product_data = array('id' => $child_id, 'price' => $child_product->get_price_excluding_tax(), 'sku' => $child_product->get_sku(), 'name' => $child_product->get_title()); $product->skus[] = $child_product_data; } } } $product->categories = array(); $product_categories = get_the_terms($product->id, 'product_cat'); if (is_array($product_categories)) { $sequence = 0; foreach ($product_categories as $category) { $product->categories[] = array('category_id' => $category->term_id, 'sequence' => $sequence); $sequence++; } } $image_sequence = 1; $product->images = array(); $imagesUsed = array(); $primaryimage_path = wp_get_attachment_image_src($wc_product->get_image_id(), 'full'); $primaryimage_path = $primaryimage_path[0]; if ($primaryimage_path) { $product->images[] = array('source' => $primaryimage_path, 'sequence' => 0); $imagesUsed[$primaryimage_path] = true; foreach ($wc_product->get_gallery_attachment_ids() as $image_id) { $image_path = wp_get_attachment_image_src($image_id, 'full'); $image_path = $image_path[0]; if (!array_key_exists($image_path, $imagesUsed)) { $product->images[] = array('source' => $image_path, 'sequence' => $image_sequence); $imagesUsed[$image_path] = true; $image_sequence++; } } } $product->attributes = array(); $attributesUsed = array(); foreach ($wc_product->get_attributes() as $attribute) { if (!$attribute['is_variation']) { if (!array_key_exists($attribute['name'], $attributesUsed)) { $attributesUsed[$attribute['name']] = true; $attributeName = wc_attribute_label($attribute['name']); if (!$attribute['is_taxonomy']) { $product->attributes[] = array('name' => $attributeName, 'value' => $attribute['value']); } else { $attributeValue = implode(', ', wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'))); $product->attributes[] = array('name' => $attributeName, 'value' => $attributeValue); } } } } foreach (get_post_custom_keys($product->id) as $attribute) { if (!(substr($attribute, 0, 1) === '_' || substr($attribute, 0, 3) === 'pa_')) { if (!array_key_exists($attribute, $attributesUsed)) { $attributesUsed[$attribute] = true; $value = get_post_meta($product->id, $attribute, false); if (is_array($value)) { if (count($value) === 1) { $value = $value[0]; } else { $value = implode(',', $value); } } $product->attributes[] = array('name' => $attribute, 'value' => $value); } } } // acf if ($acf_installed) { if (function_exists('get_field_objects')) { $fields = get_field_objects($product->id); if (is_array($fields)) { foreach ($fields as $field) { if ($field['type'] == 'image') { $image_path = $field['value']['url']; if (!array_key_exists($image_path, $imagesUsed)) { $product->images[] = array('source' => $image_path, 'sequence' => $image_sequence); $imagesUsed[$image_path] = true; $image_sequence++; } } else { if ($field['type'] == 'gallery') { $gallery = $field['value']; if (is_array($gallery)) { foreach ($gallery as $image) { $image_path = $image['url']; if (!array_key_exists($image_path, $imagesUsed)) { $product->images[] = array('source' => $image_path, 'sequence' => $image_sequence); $imagesUsed[$image_path] = true; $image_sequence++; } } } } else { if (in_array($field['type'], array('textarea', 'wysiwyg', 'text', 'number', 'select', 'radio', 'checkbox', 'true_false'))) { if (!array_key_exists($field['label'], $attributesUsed)) { $attributesUsed[$field['label']] = true; $value = $field['value']; if (is_array($value)) { if (count($value) === 1) { $value = $value[0]; } else { $value = implode(',', $value); } } $product->attributes[] = array('name' => $field['name'], 'value' => $value); } } } } if (!$product->description) { if (in_array($field['type'], array('textarea', 'wysiwyg')) && $field['name'] == 'description') { $product->description = $field['value']; } } } } } } } $response = array('ack' => 'ok', 'products' => $products); if (isset($total_count)) { $response['total_count'] = $total_count; } $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } else { if ($type === 'categories') { if (!$this->check_hash()) { exit; } $categories = get_categories(array('taxonomy' => 'product_cat', 'orderby' => 'term_order', 'hide_empty' => 0)); $result = array(); foreach ($categories as $category) { $result[] = array('category_id' => $category->term_id, 'name' => $category->name, 'parent_id' => $category->parent); } $response = array('ack' => 'ok', 'categories' => $result, 'total_count' => count($categories)); $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } else { if ($type === 'orders') { if (!$this->check_hash()) { exit; } $page = isset($_GET['page']) ? (int) $_GET['page'] : 0; $count = isset($_GET['count']) ? (int) $_GET['count'] : 0; $orders = $wpdb->get_results($wpdb->prepare("SELECT (SELECT meta_value FROM `{$wpdb->prefix}postmeta` WHERE post_id = P.id AND meta_key = '_codisto_orderid') AS id, ID AS post_id, post_status AS status FROM `{$wpdb->prefix}posts` AS P WHERE post_type = 'shop_order' AND ID IN (SELECT post_id FROM `{$wpdb->prefix}postmeta` WHERE meta_key = '_codisto_orderid') ORDER BY ID LIMIT %d, %d", $page * $count, $count)); if ($page == 0) { $total_count = $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}posts` AS P WHERE post_type = 'shop_order' AND ID IN (SELECT post_id FROM `{$wpdb->prefix}postmeta` WHERE meta_key = '_codisto_orderid')"); } $order_data = array(); foreach ($orders as $order) { $ship_date = get_post_meta($order->post_id, '_date_shipped', true); if ($ship_date) { if (is_numeric($ship_date)) { $ship_date = date('Y-m-d H:i:s', $ship_date); } $order->ship_date = $ship_date; } $carrier = get_post_meta($order->post_id, '_tracking_provider', true); if ($carrier) { if ($carrier === 'custom') { $carrier = get_post_meta($order->post_id, '_custom_tracking_provider', true); } if ($carrier) { $order->carrier = $carrier; } } $tracking_number = get_post_meta($order->post_id, '_tracking_number', true); if ($tracking_number) { $order->track_number = $tracking_number; } unset($order->post_id); $order_data[] = $order; } $response = array('ack' => 'ok', 'orders' => $order_data); if (isset($total_count)) { $response['total_count'] = $total_count; } $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } else { if ($type == 'sync') { if ($_SERVER['HTTP_X_ACTION'] === 'TEMPLATE') { if (!$this->check_hash()) { exit; } $ebayDesignDir = WP_CONTENT_DIR . '/ebay/'; $merchantid = (int) $_GET['merchantid']; if (!$merchantid) { $merchantid = 0; } $templatedb = get_temp_dir() . '/ebay-template-' . $merchantid . '.db'; $db = new PDO('sqlite:' . $templatedb); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_TIMEOUT, 60); $db->exec('PRAGMA synchronous=0'); $db->exec('PRAGMA temp_store=2'); $db->exec('PRAGMA page_size=65536'); $db->exec('PRAGMA encoding=\'UTF-8\''); $db->exec('PRAGMA cache_size=15000'); $db->exec('PRAGMA soft_heap_limit=67108864'); $db->exec('PRAGMA journal_mode=MEMORY'); $db->exec('BEGIN EXCLUSIVE TRANSACTION'); $db->exec('CREATE TABLE IF NOT EXISTS File(Name text NOT NULL PRIMARY KEY, Content blob NOT NULL, LastModified datetime NOT NULL, Changed bit NOT NULL DEFAULT -1)'); $db->exec('COMMIT TRANSACTION'); if (isset($_GET['markreceived'])) { $update = $db->prepare('UPDATE File SET LastModified = ? WHERE Name = ?'); $files = $db->query('SELECT Name FROM File WHERE Changed != 0'); $files->execute(); $db->exec('BEGIN EXCLUSIVE TRANSACTION'); while ($row = $files->fetch()) { $stat = stat(WP_CONTENT_DIR . '/ebay/' . $row['Name']); $lastModified = strftime('%Y-%m-%d %H:%M:%S', $stat['mtime']); $update->bindParam(1, $lastModified); $update->bindParam(2, $row['Name']); $update->execute(); } $db->exec('UPDATE File SET Changed = 0'); $db->exec('COMMIT TRANSACTION'); $db = null; $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, must-revalidate', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode(array('ack' => 'ok')); exit; } else { $insert = $db->prepare('INSERT OR IGNORE INTO File(Name, Content, LastModified) VALUES (?, ?, ?)'); $update = $db->prepare('UPDATE File SET Content = ?, Changed = -1 WHERE Name = ? AND LastModified != ?'); $filelist = $this->files_in_dir($ebayDesignDir); $db->exec('BEGIN EXCLUSIVE TRANSACTION'); foreach ($filelist as $key => $name) { try { $fileName = $ebayDesignDir . $name; if (!in_array($name, array('README'))) { $content = @file_get_contents($fileName); if ($content !== false) { $stat = stat($fileName); $lastModified = strftime('%Y-%m-%d %H:%M:%S', $stat['mtime']); $update->bindParam(1, $content); $update->bindParam(2, $name); $update->bindParam(3, $lastModified); $update->execute(); if ($update->rowCount() == 0) { $insert->bindParam(1, $name); $insert->bindParam(2, $content); $insert->bindParam(3, $lastModified); $insert->execute(); } } } } catch (Exception $e) { } } $db->exec('COMMIT TRANSACTION'); $tmpDb = wp_tempnam(); $db = new PDO('sqlite:' . $tmpDb); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->exec('PRAGMA synchronous=0'); $db->exec('PRAGMA temp_store=2'); $db->exec('PRAGMA page_size=512'); $db->exec('PRAGMA encoding=\'UTF-8\''); $db->exec('PRAGMA cache_size=15000'); $db->exec('PRAGMA soft_heap_limit=67108864'); $db->exec('PRAGMA journal_mode=OFF'); $db->exec('ATTACH DATABASE \'' . $templatedb . '\' AS Source'); $db->exec('CREATE TABLE File AS SELECT * FROM Source.File WHERE Changed != 0'); $db->exec('DETACH DATABASE Source'); $db->exec('VACUUM'); $fileCountStmt = $db->query('SELECT COUNT(*) AS fileCount FROM File'); $fileCountStmt->execute(); $fileCountRow = $fileCountStmt->fetch(); $fileCount = $fileCountRow['fileCount']; $db = null; if ($fileCount == 0) { $this->sendHttpHeaders('204 No Content', array('Cache-Control' => 'no-cache, must-revalidate', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); } else { $headers = array('Cache-Control' => 'no-cache, must-revalidate', 'Pragma' => 'no-cache', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Content-Type' => 'application/octet-stream', 'Content-Disposition' => 'attachment; filename=' . basename($tmpDb), 'Content-Length' => filesize($tmpDb)); $this->sendHttpHeaders('200 OK', $headers); while (ob_get_level() > 0) { if (!@ob_end_clean()) { break; } } flush(); readfile($tmpDb); } unlink($tmpDb); exit; } } } } } } } } } } else { if ($type === 'createorder') { if (!$this->check_hash()) { exit; } try { $xml = simplexml_load_string(file_get_contents('php://input')); $ordercontent = $xml->entry->content->children('http://api.codisto.com/schemas/2009/'); $wpdb->query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'); $wpdb->query('START TRANSACTION'); $billing_address = $ordercontent->orderaddresses->orderaddress[0]; $shipping_address = $ordercontent->orderaddresses->orderaddress[1]; $billing_first_name = $billing_last_name = ''; if (strpos($billing_address->name, ' ') !== false) { $billing_name = explode(' ', $billing_address->name, 2); $billing_first_name = $billing_name[0]; $billing_last_name = $billing_name[1]; } else { $billing_first_name = (string) $billing_address->name; } $billing_country_code = (string) $billing_address->countrycode; $billing_division = (string) $billing_address->division; $billing_states = WC()->countries->get_states($billing_country_code); if ($billing_states) { $billing_division_match = preg_replace('/\\s+/', '', strtolower($billing_division)); foreach ($billing_states as $state_code => $state_name) { if (preg_replace('/\\s+/', '', strtolower($state_name)) == $billing_division_match) { $billing_division = $state_code; break; } } } $shipping_first_name = $shipping_last_name = ''; if (strpos($shipping_address->name, ' ') !== false) { $shipping_name = explode(' ', $shipping_address->name, 2); $shipping_first_name = $shipping_name[0]; $shipping_last_name = $shipping_name[1]; } else { $shipping_first_name = (string) $shipping_address->name; } $shipping_country_code = (string) $shipping_address->countrycode; $shipping_division = (string) $shipping_address->division; if ($billing_country_code === $shipping_country_code) { $shipping_states = $billing_states; } else { $shipping_states = WC()->countries->get_states($shipping_country_code); } if ($shipping_states) { $shipping_division_match = preg_replace('/\\s+/', '', strtolower($shipping_division)); foreach ($shipping_states as $state_code => $state_name) { if (preg_replace('/\\s+/', '', strtolower($state_name)) == $shipping_division_match) { $shipping_division = $state_code; break; } } } $address_data = array('billing_first_name' => $billing_first_name, 'billing_last_name' => $billing_last_name, 'billing_company' => (string) $billing_address->companyname, 'billing_address_1' => (string) $billing_address->address1, 'billing_address_2' => (string) $billing_address->address2, 'billing_city' => (string) $billing_address->place, 'billing_postcode' => (string) $billing_address->postalcode, 'billing_state' => $billing_division, 'billing_country' => $billing_country_code, 'billing_email' => (string) $billing_address->email, 'billing_phone' => (string) $billing_address->phone, 'shipping_first_name' => $shipping_first_name, 'shipping_last_name' => $shipping_last_name, 'shipping_company' => (string) $shipping_address->companyname, 'shipping_address_1' => (string) $shipping_address->address1, 'shipping_address_2' => (string) $shipping_address->address2, 'shipping_city' => (string) $shipping_address->place, 'shipping_postcode' => (string) $shipping_address->postalcode, 'shipping_state' => $shipping_division, 'shipping_country' => $shipping_country_code, 'shipping_email' => (string) $shipping_address->email, 'shipping_phone' => (string) $shipping_address->phone); $email = (string) $billing_address->email; if (!$email) { $email = (string) $shipping_address->email; } if ($email) { $user = get_user_by('email', $email); if (!$user) { $username = (string) $ordercontent->ebayusername; if (!$username) { $username = current(explode('@', $email)); } if ($username) { $username = sanitize_user($username); } if (username_exists($username)) { $counter = 1; $newusername = $username . $counter; while (username_exists($newusername)) { $counter++; $newusername = $username . $counter; } $username = $newusername; } $password = wp_generate_password(); $customer_data = apply_filters('woocommerce_new_customer_data', array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'role' => 'customer')); $customer_id = wp_insert_user($customer_data); foreach ($address_data as $key => $value) { update_user_meta($customer_id, $key, $value); } do_action('woocommerce_created_customer', $customer_id, $customer_data, true); } else { $customer_id = $user->ID; } } else { $customer_id = 0; } $customer_note = @count($ordercontent->instructions) ? strval($ordercontent->instructions) : ''; $order_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM `{$wpdb->prefix}posts` AS P WHERE ID IN (SELECT post_id FROM `{$wpdb->prefix}postmeta` WHERE meta_key = '_codisto_orderid' AND meta_value = %d)", (int) $ordercontent->orderid)); $shipping = 0; $shipping_tax = 0; $cart_discount = 0; $cart_discount_tax = 0; $total = (double) $ordercontent->ordertotal; $tax = 0; if (!$order_id) { $new_order_data_callback = array($this, 'order_set_date'); add_filter('woocommerce_new_order_data', $new_order_data_callback, 1, 1); $order = wc_create_order(array('customer_id' => $customer_id, 'customer_note' => $customer_note, 'created_via' => 'eBay')); remove_filter('woocommerce_new_order_data', $new_order_data_callback); $order_id = $order->id; update_post_meta($order_id, '_codisto_orderid', (int) $ordercontent->orderid); update_post_meta($order_id, '_codisto_ebayuser', (string) $ordercontent->ebayusername); update_post_meta($order_id, '_order_currency', (string) $ordercontent->transactcurrency); update_post_meta($order_id, '_customer_ip_address', '-'); delete_post_meta($order_id, '_prices_include_tax'); do_action('woocommerce_new_order', $order_id); foreach ($ordercontent->orderlines->orderline as $orderline) { if ($orderline->productcode[0] != 'FREIGHT') { $productcode = (string) $orderline->productcode; if ($productcode == null) { $productcode = ''; } $productname = (string) $orderline->productname; if ($productname == null) { $productname = ''; } $product_id = $orderline->externalreference[0]; if ($product_id != null) { $product_id = intval($product_id); } $variation_id = 0; if (get_post_type($product_id) === 'product_variation') { $variation_id = $product_id; $product_id = wp_get_post_parent_id($variation_id); if (!is_numeric($product_id) || $product_id === 0) { $product_id = 0; $variation_id = 0; } } $qty = (int) $orderline->quantity[0]; $item_id = wc_add_order_item($order_id, array('order_item_name' => $productname, 'order_item_type' => 'line_item')); wc_add_order_item_meta($item_id, '_qty', $qty); if (!is_null($product_id) && $product_id !== 0) { wc_add_order_item_meta($item_id, '_product_id', $product_id); wc_add_order_item_meta($item_id, '_variation_id', $variation_id); wc_add_order_item_meta($item_id, '_tax_class', ''); } else { wc_add_order_item_meta($item_id, '_product_id', 0); wc_add_order_item_meta($item_id, '_variation_id', 0); wc_add_order_item_meta($item_id, '_tax_class', ''); } $line_total = wc_format_decimal((double) $orderline->linetotal); $line_total_tax = wc_format_decimal((double) $orderline->linetotalinctax - (double) $orderline->linetotal); wc_add_order_item_meta($item_id, '_line_subtotal', $line_total); wc_add_order_item_meta($item_id, '_line_total', $line_total); wc_add_order_item_meta($item_id, '_line_subtotal_tax', $line_total_tax); wc_add_order_item_meta($item_id, '_line_tax', $line_total_tax); wc_add_order_item_meta($item_id, '_line_tax_data', array('total' => array(1 => $line_total_tax), 'subtotal' => array(1 => $line_total_tax))); $tax += $line_total_tax; } else { $item_id = wc_add_order_item($order_id, array('order_item_name' => (string) $orderline->productname, 'order_item_type' => 'shipping')); wc_add_order_item_meta($item_id, 'cost', wc_format_decimal((double) $orderline->linetotal)); $shipping += (double) $orderline->linetotal; $shipping_tax += (double) $orderline->linetotalinctax - (double) $orderline->linetotal; } } if ($ordercontent->paymentstatus == 'complete') { $transaction_id = (string) $ordercontent->orderpayments[0]->orderpayment->transactionid; if ($transaction_id) { update_post_meta($order_id, '_payment_method', 'paypal'); update_post_meta($order_id, '_payment_method_title', __('PayPal', 'woocommerce')); update_post_meta($order_id, '_transaction_id', $transaction_id); } else { update_post_meta($order_id, '_payment_method', 'bacs'); update_post_meta($order_id, '_payment_method_title', __('BACS', 'woocommerce')); } // payment_complete add_post_meta($order_id, '_paid_date', current_time('mysql'), true); if (!get_post_meta($order_id, '_order_stock_reduced', true)) { $order->reduce_order_stock(); } } } else { $order = wc_get_order($order_id); foreach ($ordercontent->orderlines->orderline as $orderline) { if ($orderline->productcode[0] != 'FREIGHT') { $line_total = wc_format_decimal((double) $orderline->linetotal); $line_total_tax = wc_format_decimal((double) $orderline->linetotalinctax - (double) $orderline->linetotal); $tax += $line_total_tax; } else { $order->remove_order_items('shipping'); $item_id = wc_add_order_item($order_id, array('order_item_name' => (string) $orderline->productname, 'order_item_type' => 'shipping')); wc_add_order_item_meta($item_id, 'cost', wc_format_decimal((double) $orderline->linetotal)); $shipping += (double) $orderline->linetotal; $shipping_tax += (double) $orderline->linetotalinctax - (double) $orderline->linetotal; } } if ($ordercontent->paymentstatus == 'complete') { $transaction_id = (string) $ordercontent->orderpayments[0]->orderpayment->transactionid; if ($transaction_id) { update_post_meta($order_id, '_payment_method', 'paypal'); update_post_meta($order_id, '_payment_method_title', __('PayPal', 'woocommerce')); update_post_meta($order_id, '_transaction_id', $transaction_id); } else { update_post_meta($order_id, '_payment_method', 'bacs'); update_post_meta($order_id, '_payment_method_title', __('BACS', 'woocommerce')); } // payment_complete add_post_meta($order_id, '_paid_date', current_time('mysql'), true); if (!get_post_meta($order_id, '_order_stock_reduced', true)) { $order->reduce_order_stock(); } } } foreach ($address_data as $key => $value) { update_post_meta($order_id, '_' . $key, $value); } $order->remove_order_items('tax'); $order->add_tax(1, $tax, $shipping_tax); $order->set_total($shipping, 'shipping'); $order->set_total($shipping_tax, 'shipping_tax'); $order->set_total($cart_discount, 'cart_discount'); $order->set_total($cart_discount_tax, 'cart_discount_tax'); $order->set_total($tax, 'tax'); $order->set_total($total, 'total'); if ($ordercontent->orderstate == 'cancelled') { if (!$order->has_status('cancelled')) { // update_status $order->post_status = 'wc-cancelled'; $update_post_data = array('ID' => $order_id, 'post_status' => 'wc-cancelled', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1)); wp_update_post($update_post_data); $order->decrease_coupon_usage_counts(); wc_delete_shop_order_transients($order_id); } } else { if ($ordercontent->orderstate == 'inprogress' || $ordercontent->orderstate == 'processing') { if ($ordercontent->paymentstatus == 'complete') { if (!$order->has_status('processing')) { // update_status $order->post_status = 'wc-processing'; $update_post_data = array('ID' => $order_id, 'post_status' => 'wc-processing', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1)); wp_update_post($update_post_data); } } else { if (!$order->has_status('pending')) { // update_status $order->post_status = 'wc-pending'; $update_post_data = array('ID' => $order_id, 'post_status' => 'wc-pending', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1)); wp_update_post($update_post_data); } } } else { if ($ordercontent->orderstate == 'complete') { if (!$order->has_status('completed')) { // update_status $order->post_status = 'wc-completed'; $update_post_data = array('ID' => $order_id, 'post_status' => 'wc-completed', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1)); wp_update_post($update_post_data); $order->record_product_sales(); $order->increase_coupon_usage_counts(); update_post_meta($order_id, '_completed_date', current_time('mysql')); wc_delete_shop_order_transients($order_id); } } } } $wpdb->query('COMMIT'); $response = array('ack' => 'ok', 'orderid' => $order_id); $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } catch (Exception $e) { $wpdb->query('ROLLBACK'); $response = array('ack' => 'failed', 'message' => $e->getMessage() . ' ' . $e->getFile() . ' ' . $e->getLine()); $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode($response); exit; } } else { if ($type == 'sync') { if ($_SERVER['HTTP_X_ACTION'] === 'TEMPLATE') { if (!$this->check_hash()) { exit; } $ebayDesignDir = WP_CONTENT_DIR . '/ebay/'; $tmpPath = wp_tempnam(); @file_put_contents($tmpPath, file_get_contents('php://input')); $db = new PDO('sqlite:' . $tmpPath); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->exec('PRAGMA synchronous=0'); $db->exec('PRAGMA temp_store=2'); $db->exec('PRAGMA page_size=65536'); $db->exec('PRAGMA encoding=\'UTF-8\''); $db->exec('PRAGMA cache_size=15000'); $db->exec('PRAGMA soft_heap_limit=67108864'); $db->exec('PRAGMA journal_mode=MEMORY'); $files = $db->prepare('SELECT Name, Content FROM File'); $files->execute(); $files->bindColumn(1, $name); $files->bindColumn(2, $content); while ($files->fetch()) { $fileName = $ebayDesignDir . $name; if (strpos($name, '..') === false) { if (!file_exists($fileName)) { $dir = dirname($fileName); if (!is_dir($dir)) { mkdir($dir . '/', 0755, true); } @file_put_contents($fileName, $content); } } } $db = null; unlink($tmpPath); $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $this->json_encode(array('ack' => 'ok')); exit; } } else { if ($type == 'index/calc') { $product_ids = array(); $quantities = array(); for ($i = 0;; $i++) { if (!isset($_POST['PRODUCTCODE(' . $i . ')'])) { break; } $productid = (int) $_POST['PRODUCTID(' . $i . ')']; if (!$productid) { $productcode = $_POST['PRODUCTCODE(' . $i . ')']; $productid = wc_get_product_id_by_sku($productcode); } $productqty = $_POST['PRODUCTQUANTITY(' . $i . ')']; if (!$productqty && $productqty != 0) { $productqty = 1; } WC()->cart->add_to_cart($productid, $productqty); } WC()->customer->set_location($_POST['COUNTRYCODE'], $_POST['DIVISION'], $_POST['POSTALCODE'], $_POST['PLACE']); WC()->customer->set_shipping_location($_POST['COUNTRYCODE'], $_POST['DIVISION'], $_POST['POSTALCODE'], $_POST['PLACE']); WC()->cart->calculate_totals(); WC()->cart->calculate_shipping(); $response = ''; $idx = 0; $methods = WC()->shipping()->get_shipping_methods(); foreach ($methods as $method) { if (file_exists(plugin_dir_path(__FILE__) . 'shipping/' . $method->id)) { include plugin_dir_path(__FILE__) . 'shipping/' . $method->id; } else { foreach ($method->rates as $method => $rate) { $method_name = $rate->get_label(); if (!$method_name) { $method_name = 'Shipping'; } $method_cost = $rate->cost; if (is_numeric($method_cost)) { if (isset($rate->taxes) && is_array($rate->taxes)) { foreach ($rate->taxes as $tax) { if (is_numeric($tax)) { $method_cost += $tax; } } } $response .= ($idx > 0 ? '&' : '') . 'FREIGHTNAME(' . $idx . ')=' . rawurlencode($method_name) . '&FREIGHTCHARGEINCTAX(' . $idx . ')=' . number_format((double) $method_cost, 2, '.', ''); $idx++; } } } } $this->sendHttpHeaders('200 OK', array('Content-Type' => 'application/json', 'Cache-Control' => 'no-cache, no-store', 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma' => 'no-cache')); echo $response; exit; } } } } }
function get_fields($post_id = false, $format_value = true) { // vars $fields = get_field_objects($post_id, $format_value); $return = array(); // populate if (is_array($fields)) { foreach ($fields as $k => $field) { $return[$k] = $field['value']; } } // return return $return; }
$slug = get_permalink($page); } ?> </div> <article class="folio-info folio-info-variant-2 twelve columns"> <dl class="tabs contained horisontal clearfix"> <dd class="active"><a href="#folio-desc-1"><?php _e('Description', 'dfd'); ?> </a></dd> <?php if (function_exists('get_field_objects')) { $fields = get_field_objects(); } else { $fields = false; } if ($fields) { $i = 2; foreach ($fields as $field_name => $field) { if ($field['label']) { echo '<dd><a href="#folio-desc-' . $i . '">'; echo $field['label']; echo '</a></dd>'; $i++; } } } ?>
function get_fields($post_id = false, $format_value = true) { // vars $fields = get_field_objects($post_id, $format_value); $meta = array(); // bail early if (!$fields) { return false; } // populate foreach ($fields as $k => $field) { $meta[$k] = $field['value']; } // return return $meta; }
the_content(); ?> </div> <?php } ?> <div id="contact"> <h1>Contact</h1> <?php echo do_shortcode('[contact-form-7 id="2356" title="Formulaire de contact 1"]'); ?> <ul id="chouchous"> <h2>J'adore ! ♥</h2> <?php $favObject = get_field_objects(get_the_ID()); foreach ($favObject['chouchou']['value'] as $key => $value) { ?> <li> <a href="<?php echo $value['url']; ?> "><?php echo $value['nom']; ?> </a> </li> <?php } ?> </ul>
function get_fields($post_id = false, $format_value = true) { // vars $options = array('load_value' => true, 'format_value' => $format_value); $fields = get_field_objects($post_id, $options); if (is_array($fields)) { foreach ($fields as $k => $field) { $fields[$k] = $field['value']; } } return $fields; }
$rData = $wpdb->get_results($Rsql, OBJECT); foreach ($rData as $data) { $currCount = isset($ribbonData[$ribbon->entry_id]['ribbon'][$data->ribbonType]['count']) ? $ribbonData[$ribbon->entry_id]['ribbon'][$data->ribbonType]['count'] : 0; $ribbonData[$ribbon->entry_id]['ribbon'][$data->ribbonType]['count'] = $currCount + $data->ribbonCount; $ribbonData[$ribbon->entry_id]['ribbon'][$data->ribbonType]['data'][] = array('year' => $data->year, 'faire' => $data->location); } } foreach ($ribbonData as $entry_id => $data) { //pull by ACF field - entry id (cs format) $my_posts = get_posts(array('numberposts' => 1, 'post_type' => 'maker-entry-archive', 'meta_key' => 'entry_id', 'post_status' => 'accepted', 'meta_value' => $entry_id)); $postID = 0; if (!empty($my_posts)) { $postID = $my_posts[0]->ID; //$projectName = get_field('project_name',$postID); //$attachment_id = get_field('project_photo',$postID); $custom_fields = get_field_objects($postID); $project_name = isset($custom_fields['project_name']['value']) ? $custom_fields['project_name']['value'] : ''; $attachment_id = isset($custom_fields['project_photo']['value']) ? $custom_fields['project_photo']['value'] : ''; $project_photo = wp_get_attachment_url($attachment_id); } $blueCount = isset($data['ribbon'][0]['count']) ? $data['ribbon'][0]['count'] : 0; $redCount = isset($data['ribbon'][1]['count']) ? $data['ribbon'][1]['count'] : 0; if ($postID > 0) { echo '<div class="ribbData col-lg-3 col-md-3 col-sm-3 col-xs-3">'; echo '<a href="/mfarchives/' . $entry_id . '">'; if ($project_photo != '') { //legacy_get_resized_remote_image_url( $scheduleditem['large_img_url'], 140, 140 ); echo '<img img-responsive class="entryImg" src="' . $project_photo . '" style="width: 100%;height: 270px;" alt="' . $project_name . '">'; //echo '<img src="'. $project_photo[0].'" width="'. $project_photo[1] .'" height="'. $project_photo[2].'">'; } else { echo '<img img-responsive class="entryImg" src="/wp-content/uploads/2015/10/grey-makey.png" alt="grey" />';