本文整理汇总了PHP中WC_Product_Variation::get_variation_attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variation::get_variation_attributes方法的具体用法?PHP WC_Product_Variation::get_variation_attributes怎么用?PHP WC_Product_Variation::get_variation_attributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product_Variation
的用法示例。
在下文中一共展示了WC_Product_Variation::get_variation_attributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display_price_in_variation_option_name
function display_price_in_variation_option_name($term)
{
global $wpdb, $product;
$term_temp = $term;
$term = strtolower($term);
$term = str_replace(' ', '-', $term);
$result = $wpdb->get_col("SELECT slug FROM {$wpdb->prefix}terms WHERE name = '{$term}'");
$term_slug = !empty($result) ? $result[0] : $term;
$query = "SELECT postmeta.post_id AS product_id\nFROM {$wpdb->prefix}postmeta AS postmeta\nLEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )\nWHERE postmeta.meta_key LIKE 'attribute_%'\nAND postmeta.meta_value = '{$term_slug}'\nAND products.post_parent = {$product->id}";
$variation_id = $wpdb->get_col($query);
$parent = wp_get_post_parent_id($variation_id[0]);
if ($parent > 0) {
$_product = new WC_Product_Variation($variation_id[0]);
$testVariable = $_product->get_variation_attributes();
$itemPrice = strip_tags(woocommerce_price($_product->get_price()));
$getPrice = $_product->get_price();
$itemPriceInt = (int) $getPrice;
$term = $term_temp;
//this is where you can actually customize how the price is displayed
if ($itemPriceInt > 0) {
return $term . ' (' . $itemPrice . ' incl. GST)';
} else {
return $term . ' (' . $itemPrice . ')';
}
}
return $term;
}
示例2: format_wc_variation_for_square_api
/**
* Convert a WC Product or Variation into a Square ItemVariation
* See: https://docs.connect.squareup.com/api/connect/v1/#datatype-itemvariation
*
* @param WC_Product|WC_Product_Variation $variation
* @param bool $include_inventory
* @return array Formatted as a Square ItemVariation
*/
public static function format_wc_variation_for_square_api($variation, $include_inventory = false)
{
$formatted = array('name' => null, 'pricing_type' => null, 'price_money' => null, 'sku' => null, 'track_inventory' => null, 'inventory_alert_type' => null, 'inventory_alert_threshold' => null, 'user_data' => null);
if ($variation instanceof WC_Product) {
$formatted['name'] = __('Regular', 'woocommerce-square');
$formatted['price_money'] = array('currency_code' => apply_filters('woocommerce_square_currency', get_woocommerce_currency()), 'amount' => $variation->get_display_price() * 100);
$formatted['sku'] = $variation->get_sku();
if ($include_inventory && $variation->managing_stock()) {
$formatted['track_inventory'] = true;
}
}
if ($variation instanceof WC_Product_Variation) {
$formatted['name'] = implode(', ', $variation->get_variation_attributes());
}
return array_filter($formatted);
}
示例3: create_vars
public function create_vars()
{
global $product;
if (!is_product() || !$product->is_type('variable')) {
return;
}
$att_data_hook = get_option('mp_wc_vdopp_data_hook');
// Hook data
$att_dom_sel = get_option('mp_wc_vdopp_dom_selector');
// DOM Selector
$att_data_sel = get_option('mp_wc_vdopp_data_selector');
// Data Selector
$att_before_size = apply_filters('mp_wc_vdopp_before_size', rtrim(get_option('mp_wc_vdopp_before_size'))) . ' ';
$att_before_weight = apply_filters('mp_wc_vdopp_before_weight', rtrim(get_option('mp_wc_vdopp_before_weight'))) . ' ';
$att_after_size = apply_filters('mp_wc_vdopp_after_size', ' ' . ltrim(get_option('mp_wc_vdopp_after_size')));
$att_after_weight = apply_filters('mp_wc_vdopp_after_weight', ' ' . ltrim(get_option('mp_wc_vdopp_after_weight')));
$children = $product->get_children($args = '', $output = OBJECT);
$i = 0;
foreach ($children as $value) {
$product_variatons = new WC_Product_Variation($value);
if ($product_variatons->exists() && $product_variatons->variation_is_visible()) {
$variations = $product_variatons->get_variation_attributes();
foreach ($variations as $key => $variation) {
$this->variations[$i][$key] = $variation;
}
$weight = $product_variatons->get_weight();
if ($weight) {
$weight .= get_option('woocommerce_weight_unit');
}
$this->variations[$i]['weight'] = $weight;
$this->variations[$i]['dimensions'] = str_replace(' ', '', $product_variatons->get_dimensions());
$i++;
}
}
$this->variations = wp_json_encode($this->variations);
$params = array('variations' => $this->variations, 'att_data_hook' => $att_data_hook, 'att_dom_sel' => $att_dom_sel, 'att_data_sel' => $att_data_sel, 'att_before_size' => $att_before_size, 'att_before_weight' => $att_before_weight, 'att_after_size' => $att_after_size, 'att_after_weight' => $att_after_weight, 'num_variations' => count($variations));
// enqueue the script
wp_enqueue_script('mp_wc_variation_details');
wp_localize_script('mp_wc_variation_details', 'mp_wc_variations', $params);
}
示例4: get_attributes
/**
* Get the attributes for a product or product variation.
*
* @param WC_Product|WC_Product_Variation $product Product instance.
* @return array
*/
protected function get_attributes($product)
{
$attributes = array();
if ($product->is_type('variation')) {
// Variation attributes.
foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
$name = str_replace('attribute_', '', $attribute_name);
if (!$attribute) {
continue;
}
// Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
if (0 === strpos($attribute_name, 'attribute_pa_')) {
$option_term = get_term_by('slug', $attribute, $name);
$attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $option_term && !is_wp_error($option_term) ? $option_term->name : $attribute);
} else {
$attributes[] = array('id' => 0, 'name' => $name, 'option' => $attribute);
}
}
} else {
foreach ($product->get_attributes() as $attribute) {
if ($attribute['is_taxonomy']) {
$attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($attribute['name']), 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
} else {
$attributes[] = array('id' => 0, 'name' => $attribute['name'], 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
}
}
}
return $attributes;
}
示例5: foreach
function get_per_night_price($post_id, $days, $booking_settings, $variation_id)
{
global $wpdb;
//echo $variation_id;exit;
$product_id = $post_id;
if ($variation_id != '') {
//$booking_settings = get_post_meta($product_id, 'woocommerce_booking_settings', true);
if (isset($booking_settings['booking_block_price_enable'])) {
$_product = new WC_Product_Variation($variation_id);
$var_attributes = $_product->get_variation_attributes();
$attribute_names = str_replace("-", " ", $var_attributes);
/* Querying the database */
$j = 1;
$k = 0;
$attribute_sub_query = '';
foreach ($attribute_names as $key => $value) {
//echo "here".$value;
$attribute_sub_query .= " c" . $k . ".attribute_id = '{$j}' AND c" . $k . ".meta_value = '{$value}' AND";
$j++;
$k++;
}
$query = "SELECT c0.block_id FROM `" . $wpdb->prefix . "booking_block_price_attribute_meta` AS c0\n\t\t\t\t\t\t\t\t\tJOIN `" . $wpdb->prefix . "booking_block_price_attribute_meta` AS c1 ON c1.block_id=c0.block_id\n\t\t\t\t\t\t\t\t\tWHERE " . $attribute_sub_query . " c0.post_id = '" . $product_id . "'";
//print_r("here".$query);
$results = $wpdb->get_results($query);
//$number_of_days = strtotime($checkout_date) - strtotime($checkin_date);
$number = $days;
$e = 0;
foreach ($results as $k => $v) {
$query = "SELECT price_per_day, fixed_price FROM `" . $wpdb->prefix . "booking_block_price_meta`\n\t\t\t\t\t\t\tWHERE id = '" . $v->block_id . "' AND post_id = '" . $product_id . "' AND minimum_number_of_days <='" . $number . "' AND maximum_number_of_days >= '" . $number . "'";
//echo $query;
$results_price[$e] = $wpdb->get_results($query);
$e++;
}
$price = 0;
foreach ($results_price as $k => $v) {
if (!empty($results_price[$k])) {
if (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'value') {
$price = $booking_settings['booking_partial_payment_value_deposit'];
} elseif (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'percent') {
$sale_price = get_post_meta($variation_id, '_sale_price', true);
if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
if ($v[0]->fixed_price != 0) {
$oprice = $v[0]->fixed_price;
$pprice = "-fixed";
} else {
$oprice = $v[0]->price_per_day;
$pprice = "-per_day";
}
$price = $booking_settings['booking_partial_payment_value_deposit'] * $oprice / 100;
$price .= $pprice;
} elseif ($sale_price == '') {
$regular_price = get_post_meta($variation_id, '_regular_price', true);
$price = $booking_settings['booking_partial_payment_value_deposit'] * $regular_price / 100;
} else {
$price = $booking_settings['booking_partial_payment_value_deposit'] * $sale_price / 100;
}
} else {
if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
//echo $v[0]->fixed_price;
if ($v[0]->fixed_price != 0) {
$price = $v[0]->fixed_price;
$price .= "-fixed";
} else {
$price = $v[0]->price_per_day;
$price .= "-per_day";
}
}
}
} else {
unset($results_price[$k]);
}
}
}
} else {
$booking_settings = get_post_meta($product_id, 'woocommerce_booking_settings', true);
if (isset($booking_settings['booking_block_price_enable'])) {
//$number_of_days = strtotime($checkout_date) - strtotime($checkin_date);
$number = $days;
$query = "SELECT price_per_day, fixed_price FROM `" . $wpdb->prefix . "booking_block_price_meta`\n\t\t\t\t\t\t\tWHERE post_id = '" . $product_id . "' AND minimum_number_of_days <='" . $number . "' AND maximum_number_of_days >= '" . $number . "'";
//echo $query;
$results_price = $wpdb->get_results($query);
if (count($results_price) == 0) {
$sale_price = get_post_meta($product_id, '_sale_price', true);
if ($sale_price == '') {
$regular_price = get_post_meta($product_id, '_regular_price', true);
$price = $regular_price;
$price .= "-";
} else {
$price = $sale_price;
$price .= "-";
}
} else {
foreach ($results_price as $k => $v) {
//print_r($v);
if (!empty($results_price[$k])) {
if (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'value') {
$price = $booking_settings['booking_partial_payment_value_deposit'];
} elseif (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'percent') {
$sale_price = get_post_meta($product_id, '_sale_price', true);
if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
//.........这里部分代码省略.........
示例6: thb_product_singlepage
function thb_product_singlepage($atts, $content = null)
{
extract(shortcode_atts(array('product_id' => ''), $atts));
global $post, $product, $woocommerce, $woocommerce_loop;
$args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'p' => $product_id);
$single_product = new WP_Query($args);
$preselected_id = '0';
// check if sku is a variation
if (isset($atts['sku']) && $single_product->have_posts() && $single_product->post->post_type === 'product_variation') {
$variation = new WC_Product_Variation($single_product->post->ID);
$attributes = $variation->get_variation_attributes();
// set preselected id to be used by JS to provide context
$preselected_id = $single_product->post->ID;
// get the parent product object
$args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'p' => $single_product->post->post_parent);
$single_product = new WP_Query($args);
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var $variations_form = $( '[data-product-page-preselected-id="<?php
echo esc_attr($preselected_id);
?>
"]' ).find( 'form.variations_form' );
<?php
foreach ($attributes as $attr => $value) {
?>
$variations_form.find( 'select[name="<?php
echo esc_attr($attr);
?>
"]' ).val( '<?php
echo $value;
?>
' );
<?php
}
?>
});
</script>
<?php
}
ob_start();
while ($single_product->have_posts()) {
$single_product->the_post();
wp_enqueue_script('wc-single-product');
?>
<div class="single-product single-product-shortcode full-height-content" data-product-page-preselected-id="<?php
echo esc_attr($preselected_id);
?>
">
<?php
wc_get_template_part('content', 'single-product');
?>
</div>
<?php
}
// end of the loop.
wp_reset_postdata();
$out = ob_get_contents();
if (ob_get_contents()) {
ob_end_clean();
}
return $out;
}
示例7: array
function column_title($post)
{
global $woocommerce;
$post_to_edit_id = $post->post_type == 'product' ? $post->ID : $post->post_parent;
$edit_link = admin_url('post.php?post=' . $post_to_edit_id . '&action=edit');
$view_link = esc_url(add_query_arg('preview', 'true', get_permalink($post_to_edit_id)));
//Build row actions
$actions = array('edit' => '<a href="' . $edit_link . '">' . __('Edit') . '</a>', 'view' => '<a href="' . $view_link . '">' . __('View') . '</a>');
if ($post->post_type == 'product_variation' && $this->last_product_id == $post->post_parent) {
$post_title = '';
} else {
$post_title = $post->post_title;
}
// Get variations
if ($post->post_type == 'product_variation') {
$post_title = trim(current(explode('-', $post_title)));
$post_title .= ' — ';
if (function_exists('get_product')) {
$variable_product = get_product($post->ID);
} else {
$variable_product = new WC_Product_Variation($post->ID);
}
$list_attributes = array();
$attributes = $variable_product->get_variation_attributes();
foreach ($attributes as $name => $attribute) {
$list_attributes[] = $woocommerce->attribute_label(str_replace('attribute_', '', $name)) . ': <strong>' . $attribute . '</strong>';
}
$post_title .= implode(', ', $list_attributes);
}
//Return the title contents
return sprintf('%1$s %2$s', $post_title, $this->row_actions($actions));
}
示例8: product_page
/**
* Show a single product page.
*
* @param array $atts
* @return string
*/
public static function product_page($atts)
{
if (empty($atts)) {
return '';
}
if (!isset($atts['id']) && !isset($atts['sku'])) {
return '';
}
$args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1);
if (isset($atts['sku'])) {
$args['meta_query'][] = array('key' => '_sku', 'value' => sanitize_text_field($atts['sku']), 'compare' => '=');
$args['post_type'] = array('product', 'product_variation');
}
if (isset($atts['id'])) {
$args['p'] = absint($atts['id']);
}
$single_product = new WP_Query($args);
$preselected_id = '0';
// check if sku is a variation
if (isset($atts['sku']) && $single_product->have_posts() && $single_product->post->post_type === 'product_variation') {
$variation = new WC_Product_Variation($single_product->post->ID);
$attributes = $variation->get_variation_attributes();
// set preselected id to be used by JS to provide context
$preselected_id = $single_product->post->ID;
// get the parent product object
$args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'p' => $single_product->post->post_parent);
$single_product = new WP_Query($args);
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
var $variations_form = $( '[data-product-page-preselected-id="<?php
echo esc_attr($preselected_id);
?>
"]' ).find( 'form.variations_form' );
<?php
foreach ($attributes as $attr => $value) {
?>
$variations_form.find( 'select[name="<?php
echo esc_attr($attr);
?>
"]' ).val( '<?php
echo $value;
?>
' );
<?php
}
?>
});
</script>
<?php
}
ob_start();
while ($single_product->have_posts()) {
$single_product->the_post();
wp_enqueue_script('wc-single-product');
?>
<div class="single-product" data-product-page-preselected-id="<?php
echo esc_attr($preselected_id);
?>
">
<?php
wc_get_template_part('content', 'single-product');
?>
</div>
<?php
}
// end of the loop.
wp_reset_postdata();
return '<div class="woocommerce">' . ob_get_clean() . '</div>';
}
示例9: single_product_buy_button
/**
* This function shows the buy for credit button on products page
* @param int $attr
*/
function single_product_buy_button($attr)
{
global $translate;
global $product;
$class = '';
extract(shortcode_atts(array('class' => 'class', 'title' => 'title'), $attr));
if ($class !== 'class') {
$class = 'class="' . $class . '"';
} else {
$class = 'class="creditsBuyButton button"';
}
if ($product->product_type == 'variable') {
$available_variations = $product->get_available_variations();
if (!empty($available_variations)) {
foreach ($available_variations as $variation) {
$variation = new WC_Product_Variation($variation['variation_id']);
$title = $variation->get_price() . ' ' . $translate->wooTranslate('Credits', get_bloginfo('language')) . ' - ' . implode(', ', $variation->get_variation_attributes());
echo '<a ' . $class . ' href="javascript:void(0);" onclick="creditdeduct(' . $product->id . ',' . $variation->get_price() . ',' . $variation->variation_id . ')" >' . $title . '</a><br/>';
}
}
} else {
if ($title === 'title') {
$title = $product->price . ' ' . $translate->wooTranslate('Credits', get_bloginfo('language'));
}
echo '<a ' . $class . ' href="javascript:void(0);" onclick="creditdeduct(' . $product->id . ',' . $product->price . ')" >' . $title . '</a>';
}
}
示例10: get_attributes
/**
* Get the attributes for a product or product variation.
*
* @param WC_Product|WC_Product_Variation $product
* @return array
*/
protected function get_attributes($product)
{
$attributes = array();
if ($product->is_type('variation')) {
// Variation attributes.
foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
$name = str_replace('attribute_', '', $attribute_name);
// Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
if (0 === strpos($attribute_name, 'attribute_pa_')) {
$attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $attribute);
} else {
$attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $name), 'option' => $attribute);
}
}
} else {
foreach ($product->get_attributes() as $attribute) {
// Taxonomy-based attributes are comma-separated, others are pipe (|) separated.
if ($attribute['is_taxonomy']) {
$attributes[] = array('id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name($attribute['name']) : 0, 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', explode(',', $product->get_attribute($attribute['name']))));
} else {
$attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', explode('|', $product->get_attribute($attribute['name']))));
}
}
}
return $attributes;
}
示例11: custom_process
public function custom_process($order_id)
{
$order = new WC_Order($order_id);
$items = $order->get_items();
$index = 1;
// for each order item
foreach ($items as $item) {
$tixids = array();
$eid = get_post_meta($item['product_id'], '_eventid', true);
// Make sure these are indeed ticket sales
//$terms = wp_get_post_terms($item['product_id'], 'product_cat', array('fields'=>'names'));
// Check if these order items are event ticket items
if (!empty($eid)) {
// get order post meta array
$order_meta = get_post_custom($order_id, true);
$user_id_ = $order_meta['_customer_user'][0];
// Specify order type only for ticket sale
if ($index == 1) {
update_post_meta($order_id, '_order_type', 'evotix');
}
// get repeat interval for order item
$item_meta = !empty($item['Event-Time']) ? $item['Event-Time'] : false;
if ($item_meta) {
$ri__ = explode('[RI', $item_meta);
$ri_ = explode(']', $ri__[1]);
$ri = $ri_[0];
} else {
$ri = 0;
}
// Get customer information
if ($user_id_ == 0) {
// checkout without creating account
$_user = array('name' => $order_meta['_billing_first_name'][0] . ' ' . $order_meta['_billing_last_name'][0], 'email' => $order_meta['_billing_email'][0]);
} else {
//$myuser_id = $order->user_id;
$usermeta = get_user_meta($user_id_);
$_user = array('name' => $usermeta['first_name'][0] . ' ' . $usermeta['last_name'][0], 'email' => $usermeta['billing_email'][0]);
}
// create new event ticket post
if ($created_tix_id = $this->create_post()) {
$ticket_ids = $ticket_ids_ = array();
// variation product
if (!empty($item['variation_id'])) {
$_product = new WC_Product_Variation($item['variation_id']);
$hh = $_product->get_variation_attributes();
foreach ($hh as $f => $v) {
$type = $v;
}
} else {
$type = 'Normal';
}
// ticket ID(s)
$tid = $created_tix_id . '-' . $order_id . '-' . (!empty($item['variation_id']) ? $item['variation_id'] : $item['product_id']);
if ($item['qty'] > 1) {
$_tid = '';
$str = 'A';
for ($x = 0; $x < $item['qty']; $x++) {
// each ticket in item
$strng = $x == 0 ? $str : ++$str;
$ticket_ids[$tid . $strng] = 'check-in';
$ticket_ids_[] = $tid . $strng;
}
} else {
// just one ticket
$ticket_ids[$tid] = 'check-in';
$ticket_ids_[] = $tid;
}
// save ticket data
$this->create_custom_fields($created_tix_id, 'name', $_user['name']);
$this->create_custom_fields($created_tix_id, 'email', $_user['email']);
$this->create_custom_fields($created_tix_id, 'qty', $item['qty']);
$this->create_custom_fields($created_tix_id, 'cost', $order->get_line_subtotal($item));
$this->create_custom_fields($created_tix_id, 'type', $type);
$this->create_custom_fields($created_tix_id, 'ticket_ids', $ticket_ids);
$this->create_custom_fields($created_tix_id, 'wcid', $item['product_id']);
$this->create_custom_fields($created_tix_id, 'tix_status', 'none');
$this->create_custom_fields($created_tix_id, 'status', 'check-in');
$this->create_custom_fields($created_tix_id, '_eventid', $eid);
$this->create_custom_fields($created_tix_id, '_orderid', $order_id);
$this->create_custom_fields($created_tix_id, '_customerid', $user_id_);
$this->create_custom_fields($created_tix_id, 'repeat_interval', $ri);
// save event ticket id to order id
$tixids = get_post_meta($order_id, '_tixids', true);
if (is_array($tixids)) {
// if previously saved tixid array
$tixids_ = array_merge($tixids, $ticket_ids_);
} else {
// empty of saved as string
$tixids_ = $ticket_ids_;
}
// save ticket ids as array
update_post_meta($order_id, '_tixids', $tixids_);
// update product capacity if repeat interval capacity is set
// seperately per individual repeat interval
$emeta = get_post_meta($eid);
if (evo_check_yn($emeta, '_manage_repeat_cap') && evo_check_yn($emeta, 'evcal_repeat') && !empty($emeta['repeat_intervals']) && !empty($emeta['ri_capacity'])) {
// repeat capacity values for this event
$ri_capacity = unserialize($emeta['ri_capacity'][0]);
// repeat capacity for this repeat interval
$capacity_for_this_event = $ri_capacity[$ri];
//.........这里部分代码省略.........
示例12: wpmp_content_invoice
public function wpmp_content_invoice($order, $order_detail_by_order_id)
{
$msg = '<!-- Content -->';
$msg .= '<table border="0" cellpadding="20" cellspacing="0" width="100%">';
$msg .= '<tr>';
$msg .= '<td valign="top" style="padding: 48px;">';
$msg .= '<div id="body_content_inner" style="color: #737373; font-size: 14px; line-height: 150%; text-align: left;"">';
$msg .= '<p style="margin: 0 0 16px;">You have received an order from ' . $order->billing_first_name . ' ' . $order->billing_last_name . '. The order is as follows:</p>';
$msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;"">';
$msg .= 'Order #' . $order->id . ' ( ' . date_i18n(wc_date_format(), strtotime($order->order_date)) . ' )';
$msg .= '</h2>';
$msg .= '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">';
$msg .= '<thead>';
$msg .= '<tr>';
$msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Product</th>';
$msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Quantity</th>';
$msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Price</th>';
$msg .= '</tr>';
$msg .= '</thead>';
$msg .= '<tbody>';
$total_payment = 0;
$cur_symbol = get_woocommerce_currency_symbol(get_option('woocommerce_currency'));
foreach ($order_detail_by_order_id as $product_id => $details) {
for ($i = 0; $i < count($details); $i++) {
$total_payment = $total_payment + intval($details[$i]['product_total_price']);
if ($details[$i]['variable_id'] == 0) {
$msg .= '<tr>';
$msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name'];
$msg .= '<br>';
$msg .= '<small></small>';
$msg .= '</td>';
$msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>';
$msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">';
$msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>';
$msg .= '</td>';
$msg .= '</tr>';
} else {
$product = new WC_Product($product_id);
$attribute = $product->get_attributes();
$attribute_name = '';
foreach ($attribute as $key => $value) {
$attribute_name = $value['name'];
}
$variation = new WC_Product_Variation($details[$i]['variable_id']);
$aaa = $variation->get_variation_attributes();
$attribute_prop = strtoupper($aaa['attribute_' . strtolower($attribute_name)]);
$msg .= '<tr>';
$msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name'];
$msg .= '<br><small>' . $attribute_name . ':' . $attribute_prop . '</small>';
$msg .= '</td>';
$msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>';
$msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">';
$msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>';
$msg .= '</td>';
$msg .= '</tr>';
}
}
}
$msg .= '</tbody>';
$msg .= '<tfoot>';
/*$msg .= '<!-- <tr>';
$msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">Subtotal:</th>';
$msg .= '<td style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">';
$msg .= '<span class="amount"></span>';
$msg .= '</td>';
$msg .= '</tr> -->';*/
$msg .= '<tr>';
$msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Shipping:</th>';
$msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->get_shipping_method() . '</td>';
$msg .= '</tr>';
$msg .= '<tr>';
$msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Payment Method:</th>';
$msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->payment_method_title . '</td>';
$msg .= '</tr>';
$msg .= '<tr>';
$msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Total:</th>';
$msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">';
$msg .= '<span class="amount">' . $total_payment . '</span>';
$msg .= '</td>';
$msg .= '</tr>';
$msg .= '</tfoot>';
$msg .= '</table>';
$msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;">Customer details</h2>';
$msg .= '<p style="margin: 0 0 16px;">';
$msg .= '<strong>Email:</strong>';
if ($order->billing_email) {
$msg .= $order->billing_email;
}
$msg .= '</p>';
$msg .= '<p style="margin: 0 0 16px;">';
$msg .= '<strong>Tel:</strong>';
if ($order->billing_phone) {
$msg .= $order->billing_phone;
}
$msg .= '</p>';
$msg .= '<table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">';
$msg .= '<tr>';
$msg .= '<td valign="top" width="50%" style="padding: 12px;">';
$font = ' font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;';
$msg .= "<h3 style='color: #557da1; display: block;" . $font . " font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Billing address</h3>";
//.........这里部分代码省略.........
示例13: foreach
echo eventon_get_custom_language($evo_options_2, 'evoTX_005a', 'Event Time');
?>
</p>
<p style='<?php
echo $__styles_03;
?>
'><?php
echo $event_time;
?>
</p>
<?php
if (!empty($ticket_item['variation_id'])) {
$_product = new WC_Product_Variation($ticket_item['variation_id']);
$hh = $_product->get_variation_attributes();
foreach ($hh as $f => $v) {
if (empty($v)) {
continue;
}
?>
<p style='<?php
echo $__styles_03;
?>
'><span style='<?php
echo $__styles_02a;
?>
'><?php
echo eventon_get_custom_language($evo_options_2, 'evoTX_006', 'Type');
?>
:</span> <?php
示例14: bf_wc_variations_custom
function bf_wc_variations_custom($thepostid, $customfield)
{
global $variation_data, $post;
$post = get_post($thepostid);
$variation_data = new WC_Product_Variation($post);
$variation_data->get_variation_attributes();
$variation_data = (array) $variation_data;
echo '<pre>';
print_r($variation_data);
echo '</pre>';
extract($variation_data);
?>
<div class="woocommerce_variation wc-metabox closed">
<h3>
<a href="#" class="remove_variation delete" rel="<?php
echo esc_attr($variation_id);
?>
"><?php
_e('Remove', 'woocommerce');
?>
</a>
<div class="handlediv" title="<?php
esc_attr_e('Click to toggle', 'woocommerce');
?>
"></div>
<div class="tips sort" data-tip="<?php
esc_attr_e('Drag and drop, or click to set menu order manually', 'woocommerce');
?>
"></div>
<strong>#<?php
echo esc_html($variation_id);
?>
: </strong>
<?php
if (isset($parent_data)) {
foreach ($parent_data['attributes'] as $attribute) {
// Only deal with attributes that are variations
if (!$attribute['is_variation']) {
continue;
}
// Get current value for variation (if set)
$variation_selected_value = isset($variation_data['attribute_' . sanitize_title($attribute['name'])]) ? $variation_data['attribute_' . sanitize_title($attribute['name'])] : '';
// Name will be something like attribute_pa_color
echo '<select name="attribute_' . sanitize_title($attribute['name']) . '[' . $loop . ']"><option value="">' . __('Any', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '…</option>';
// Get terms for attribute taxonomy or value if its a custom attribute
if ($attribute['is_taxonomy']) {
$post_terms = wp_get_post_terms($parent_data['id'], $attribute['name']);
foreach ($post_terms as $term) {
echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>';
}
} else {
$options = wc_get_text_attributes($attribute['value']);
foreach ($options as $option) {
$selected = sanitize_title($variation_selected_value) === $variation_selected_value ? selected($variation_selected_value, sanitize_title($option), false) : selected($variation_selected_value, $option, false);
echo '<option ' . $selected . ' value="' . esc_attr($option) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
}
}
echo '</select>';
}
}
?>
<input type="hidden" name="variable_post_id[<?php
echo $loop;
?>
]" value="<?php
echo esc_attr($variation_id);
?>
" />
<input type="hidden" class="variation_menu_order" name="variation_menu_order[<?php
echo $loop;
?>
]" value="<?php
echo absint($menu_order);
?>
" />
</h3>
<div class="woocommerce_variable_attributes wc-metabox-content" style="display: none;">
<div class="data">
<p class="form-row form-row-first upload_image">
<a href="#" class="upload_image_button tips <?php
if ($_thumbnail_id > 0) {
echo 'remove';
}
?>
" data-tip="<?php
if ($_thumbnail_id > 0) {
echo __('Remove this image', 'woocommerce');
} else {
echo __('Upload an image', 'woocommerce');
}
?>
" rel="<?php
echo esc_attr($variation_id);
?>
"><img src="<?php
if (!empty($image)) {
echo esc_attr($image);
} else {
echo esc_attr(wc_placeholder_img_src());
}
//.........这里部分代码省略.........
示例15: filter_woocommerce_add_to_cart_validation
/**
*
*/
public function filter_woocommerce_add_to_cart_validation($valid, $product_id, $quantity, $variation_id = '', $variations = '')
{
global $woocommerce;
$product = wc_get_product($product_id);
if ($product->product_type === "variable") {
$deductornot = get_post_meta($variation_id, '_deductornot', true);
$deductamount = get_post_meta($variation_id, '_deductamount', true);
$getvarclass = new WC_Product_Variation($variation_id);
//reset($array);
$aatrs = $getvarclass->get_variation_attributes();
foreach ($aatrs as $key => $value) {
$slug = $value;
$cat = str_replace('attribute_', '', $key);
}
$titlevaria = get_term_by('slug', $slug, $cat);
$backorder = get_post_meta($product->post->ID, '_backorders', true);
$string = WC_Cart::get_item_data($cart_item, $flat);
//var_dump($string);
if ($backorder == 'no') {
if ($deductornot == "yes") {
$currentstock = $product->get_stock_quantity();
$reduceamount = intval($quantity) * intval($deductamount);
$currentavail = intval($currentstock / $deductamount);
if ($reduceamount > $currentstock) {
$valid = false;
wc_add_notice('' . __('You that goes over our availble stock amount.', 'woocommerce') . __('We have: ', 'woocommerce') . $currentavail . ' ' . $product->post->post_title . ' ' . $titlevaria->name . '\'s ' . __(' available.', 'woocommerce'), 'error');
return $valid;
} else {
$valid = true;
return $valid;
}
} else {
return true;
}
}
}
return true;
}