本文整理汇总了PHP中WC_Order::get_shipping方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order::get_shipping方法的具体用法?PHP WC_Order::get_shipping怎么用?PHP WC_Order::get_shipping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Order
的用法示例。
在下文中一共展示了WC_Order::get_shipping方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: woocommerce_ecommerce_tracking_piwik
/**
* ecommerce tracking with piwik.
*
* @access public
* @param int $order_id
* @return void
*/
function woocommerce_ecommerce_tracking_piwik($order_id)
{
global $woocommerce;
// Don't track admin
if (current_user_can('manage_options')) {
return;
}
// Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
$wp_piwik_global_settings = get_option('wp-piwik_global-settings');
// Return if Piwik settings are not here, or if global is not set
if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
return;
}
if (!isset($GLOBALS['wp_piwik'])) {
return;
}
// Get the order and get tracking code
$order = new WC_Order($order_id);
ob_start();
?>
try {
// Add order items
<?php
if ($order->get_items()) {
foreach ($order->get_items() as $item) {
$_product = $order->get_product_from_item($item);
?>
piwikTracker.addEcommerceItem(
"<?php
echo esc_js($_product->get_sku());
?>
", // (required) SKU: Product unique identifier
"<?php
echo esc_js($item['name']);
?>
", // (optional) Product name
"<?php
if (isset($_product->variation_data)) {
echo esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
}
?>
", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
<?php
echo esc_js($order->get_item_total($item));
?>
, // (recommended) Product price
<?php
echo esc_js($item['qty']);
?>
// (optional, default to 1) Product quantity
);
<?php
}
}
?>
// Track order
piwikTracker.trackEcommerceOrder(
"<?php
echo esc_js($order->get_order_number());
?>
", // (required) Unique Order ID
<?php
echo esc_js($order->get_total());
?>
, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
false, // (optional) Order sub total (excludes shipping)
<?php
echo esc_js($order->get_total_tax());
?>
, // (optional) Tax amount
<?php
echo esc_js($order->get_shipping());
?>
, // (optional) Shipping amount
false // (optional) Discount offered (set to false for unspecified parameter)
);
} catch( err ) {}
<?php
$code = ob_get_clean();
$woocommerce->add_inline_js($code);
}
示例2: woocommerce_ecommerce_tracking_piwik
/**
* ecommerce tracking with piwik
*/
function woocommerce_ecommerce_tracking_piwik($order_id)
{
global $woocommerce;
if (is_admin()) {
return;
}
// Don't track admin
// Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
$wp_piwik_global_settings = get_option('wp-piwik_global-settings');
// Return if Piwik settings are not here, or if global is not set
if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
return;
}
if (!isset($GLOBALS['wp_piwik'])) {
return;
}
// Remove WP-Piwik from wp_footer and run it here instead, to get Piwik
// loaded *before* we do our ecommerce tracking calls
remove_action('wp_footer', array($GLOBALS['wp_piwik'], 'footer'));
$GLOBALS['wp_piwik']->footer();
// Get the order and output tracking code
$order = new WC_Order($order_id);
?>
<script type="text/javascript">
try {
// Add order items
<?php
if ($order->get_items()) {
foreach ($order->get_items() as $item) {
$_product = $order->get_product_from_item($item);
?>
piwikTracker.addEcommerceItem(
"<?php
echo $_product->sku;
?>
", // (required) SKU: Product unique identifier
"<?php
echo $item['name'];
?>
", // (optional) Product name
"<?php
if (isset($_product->variation_data)) {
echo woocommerce_get_formatted_variation($_product->variation_data, true);
}
?>
", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
<?php
echo $item['line_cost'] / $item['qty'];
?>
, // (recommended) Product price
<?php
echo $item['qty'];
?>
// (optional, default to 1) Product quantity
);
<?php
}
}
?>
// Track order
piwikTracker.trackEcommerceOrder(
"<?php
echo $order_id;
?>
", // (required) Unique Order ID
<?php
echo $order->order_total;
?>
, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
false, // (optional) Order sub total (excludes shipping)
<?php
echo $order->get_total_tax();
?>
, // (optional) Tax amount
<?php
echo $order->get_shipping();
?>
, // (optional) Shipping amount
false // (optional) Discount offered (set to false for unspecified parameter)
);
} catch( err ) {}
</script>
<?php
}
示例3: process_payment
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
public function process_payment($order_id)
{
global $woocommerce;
$this->init_mijireh();
$mj_order = new Mijireh_Order();
$wc_order = new WC_Order($order_id);
// add items to order
$items = $wc_order->get_items();
foreach ($items as $item) {
$product = $wc_order->get_product_from_item($item);
$mj_order->add_item($item['name'], $wc_order->get_item_subtotal($item), $item['qty'], $product->get_sku());
}
// add billing address to order
$billing = new Mijireh_Address();
$billing->first_name = $wc_order->billing_first_name;
$billing->last_name = $wc_order->billing_last_name;
$billing->street = $wc_order->billing_address_1;
$billing->apt_suite = $wc_order->billing_address_2;
$billing->city = $wc_order->billing_city;
$billing->state_province = $wc_order->billing_state;
$billing->zip_code = $wc_order->billing_postcode;
$billing->country = $wc_order->billing_country;
$billing->company = $wc_order->billing_company;
$billing->phone = $wc_order->billing_phone;
if ($billing->validate()) {
$mj_order->set_billing_address($billing);
}
// add shipping address to order
$shipping = new Mijireh_Address();
$shipping->first_name = $wc_order->shipping_first_name;
$shipping->last_name = $wc_order->shipping_last_name;
$shipping->street = $wc_order->shipping_address_1;
$shipping->apt_suite = $wc_order->shipping_address_2;
$shipping->city = $wc_order->shipping_city;
$shipping->state_province = $wc_order->shipping_state;
$shipping->zip_code = $wc_order->shipping_postcode;
$shipping->country = $wc_order->shipping_country;
$shipping->company = $wc_order->shipping_company;
if ($shipping->validate()) {
$mj_order->set_shipping_address($shipping);
}
// set order name
$mj_order->first_name = $wc_order->billing_first_name;
$mj_order->last_name = $wc_order->billing_last_name;
$mj_order->email = $wc_order->billing_email;
// set order totals
$mj_order->total = $wc_order->get_order_total();
$mj_order->tax = $wc_order->get_total_tax();
$mj_order->discount = $wc_order->get_total_discount();
$mj_order->shipping = $wc_order->get_shipping();
// add meta data to identify woocommerce order
$mj_order->add_meta_data('wc_order_id', $order_id);
// Set URL for mijireh payment notificatoin - use WC API
$mj_order->return_url = str_replace('https:', 'http:', add_query_arg('wc-api', 'WC_Mijireh_Checkout', home_url('/')));
// Identify woocommerce
$mj_order->partner_id = 'woo';
try {
$mj_order->create();
$result = array('result' => 'success', 'redirect' => $mj_order->checkout_url);
return $result;
} catch (Mijireh_Exception $e) {
$woocommerce->add_error(__('Mijireh error:', 'woocommerce') . $e->getMessage());
}
}
示例4: array
/**
* Google Analytics eCommerce tracking
*
* @access public
* @param mixed $order_id
* @return void
*/
function ecommerce_tracking_code($order_id)
{
global $woocommerce;
if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1) {
return;
}
$tracking_id = $this->ga_id;
if (!$tracking_id) {
return;
}
// Doing eCommerce tracking so unhook standard tracking from the footer
remove_action("wp_footer", array($this, "ee_settings"));
// Get the order and output tracking code
$order = new WC_Order($order_id);
//Get Applied Coupon Codes
$coupons_list = '';
if ($order->get_used_coupons()) {
$coupons_count = count($order->get_used_coupons());
$i = 1;
foreach ($order->get_used_coupons() as $coupon) {
$coupons_list .= $coupon;
if ($i < $coupons_count) {
$coupons_list .= ', ';
}
$i++;
}
}
//get domain name if value is set
if (!empty($this->ga_Dname)) {
$set_domain_name = esc_js($this->ga_Dname);
} else {
$set_domain_name = "auto";
}
//add display features
if ($this->ga_DF) {
$ga_display_feature_code = 'ga("require", "displayfeatures");';
} else {
$ga_display_feature_code = "";
}
//add Pageview on order page if user checked Add Standard UA code
if ($this->ga_ST) {
$ga_pageview = 'ga("send", "pageview");';
} else {
$ga_pageview = "";
}
$code = '(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
ga("create", "' . esc_js($tracking_id) . '", "' . $set_domain_name . '");
' . $ga_display_feature_code . '
ga("require", "ec", "ec.js");
' . $ga_pageview . '
';
// Order items
if ($order->get_items()) {
foreach ($order->get_items() as $item) {
$_product = $order->get_product_from_item($item);
if (isset($_product->variation_data)) {
$categories = esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
} else {
$out = array();
$categories = get_the_terms($_product->id, "product_cat");
if ($categories) {
foreach ($categories as $category) {
$out[] = $category->name;
}
}
$categories = esc_js(join(",", $out));
}
//orderpage Prod json
$orderpage_prod_Array[get_permalink($_product->id)] = array("tvc_id" => esc_html($_product->id), "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id), "tvc_n" => esc_js($item["name"]), "tvc_p" => esc_js($order->get_item_total($item)), "tvc_c" => $categories, "tvc_q" => esc_js($item["qty"]));
}
//make json for prod meta data on order page
$this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
}
//get shipping cost based on version >2.1 get_total_shipping() < get_shipping
if (version_compare($woocommerce->version, "2.1", ">=")) {
$tvc_sc = $order->get_total_shipping();
} else {
$tvc_sc = $order->get_shipping();
}
//orderpage transcation data json
$orderpage_trans_Array = array("id" => esc_js($order->get_order_number()), "affiliation" => esc_js(get_bloginfo('name')), "revenue" => esc_js($order->get_total()), "tax" => esc_js($order->get_total_tax()), "shipping" => esc_js($tvc_sc), "coupon" => $coupons_list);
//make json for trans data on order page
$this->wc_version_compare("tvc_td=" . json_encode($orderpage_trans_Array) . ";");
$code .= '
//set local currencies
ga("set", "&cu", tvc_lc);
for(var t_item in tvc_oc){
ga("ec:addProduct", {
"id": tvc_oc[t_item].tvc_i,
//.........这里部分代码省略.........
开发者ID:developmentDM2,项目名称:The-Haute-Mess,代码行数:101,代码来源:class-wc-enhanced-ecommerce-google-analytics-integration.php
示例5: array
/**
* Google Analytics eCommerce tracking
*
* @access public
* @param mixed $order_id
* @return void
*/
function ecommerce_tracking_code($order_id)
{
global $woocommerce;
if ($this->ga_ecommerce_tracking_enabled == "no" || current_user_can('manage_options') || get_post_meta($order_id, '_ga_tracked', true) == 1) {
return;
}
$tracking_id = $this->ga_id;
if (!$tracking_id) {
return;
}
// Doing eCommerce tracking so unhook standard tracking from the footer
remove_action('wp_footer', array($this, 'google_tracking_code'));
// Get the order and output tracking code
$order = new WC_Order($order_id);
$loggedin = is_user_logged_in() ? 'yes' : 'no';
if (is_user_logged_in()) {
$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
$username = $current_user->user_login;
} else {
$user_id = '';
$username = __('Guest', 'woocommerce');
}
if (!empty($this->ga_set_domain_name)) {
$set_domain_name = "['_setDomainName', '" . esc_js($this->ga_set_domain_name) . "'],";
} else {
$set_domain_name = '';
}
$code = "\r\n\t\t\tvar _gaq = _gaq || [];\r\n\r\n\t\t\t_gaq.push(\r\n\t\t\t\t['_setAccount', '" . esc_js($tracking_id) . "'], " . $set_domain_name . "\r\n\t\t\t\t['_setCustomVar', 1, 'logged-in', '" . esc_js($loggedin) . "', 1],\r\n\t\t\t\t['_trackPageview']\r\n\t\t\t);\r\n\r\n\t\t\t_gaq.push(['_addTrans',\r\n\t\t\t\t'" . esc_js($order->get_order_number()) . "', // order ID - required\r\n\t\t\t\t'" . esc_js(get_bloginfo('name')) . "', \t// affiliation or store name\r\n\t\t\t\t'" . esc_js($order->get_total()) . "', \t // total - required\r\n\t\t\t\t'" . esc_js($order->get_total_tax()) . "', // tax\r\n\t\t\t\t'" . esc_js($order->get_shipping()) . "',\t // shipping\r\n\t\t\t\t'" . esc_js($order->billing_city) . "', // city\r\n\t\t\t\t'" . esc_js($order->billing_state) . "', // state or province\r\n\t\t\t\t'" . esc_js($order->billing_country) . "' // country\r\n\t\t\t]);\r\n\t\t";
// Order items
if ($order->get_items()) {
foreach ($order->get_items() as $item) {
$_product = $order->get_product_from_item($item);
$code .= "_gaq.push(['_addItem',";
$code .= "'" . esc_js($order->get_order_number()) . "',";
$code .= "'" . esc_js($_product->get_sku() ? __('SKU:', 'woocommerce') . ' ' . $_product->get_sku() : $_product->id) . "',";
$code .= "'" . esc_js($item['name']) . "',";
if (isset($_product->variation_data)) {
$code .= "'" . esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)) . "',";
} else {
$out = array();
$categories = get_the_terms($_product->id, 'product_cat');
if ($categories) {
foreach ($categories as $category) {
$out[] = $category->name;
}
}
$code .= "'" . esc_js(join("/", $out)) . "',";
}
$code .= "'" . esc_js($order->get_item_total($item, true, true)) . "',";
$code .= "'" . esc_js($item['qty']) . "'";
$code .= "]);";
}
}
$code .= "\r\n\t\t\t_gaq.push(['_trackTrans']); \t\t\t\t\t// submits transaction to the Analytics servers\r\n\r\n\t\t\t(function() {\r\n\t\t\t\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r\n\t\t\t\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r\n\t\t\t\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r\n\t\t\t})();\r\n\t\t";
echo '<script type="text/javascript">' . $code . '</script>';
update_post_meta($order_id, '_ga_tracked', 1);
}
示例6: get_total_shipping
/**
* Returns the total shipping cost for the given order
*
* @since 2.0
* @param WC_Order $order
* @return float the shipping total
*/
public static function get_total_shipping($order)
{
if (self::is_wc_version_gte_2_1()) {
return $order->get_total_shipping();
} else {
return $order->get_shipping();
}
}
示例7: onWooCheckout
public function onWooCheckout($order_id, $posted)
{
$order = new WC_Order($order_id);
$purchaseAmount = $order->get_total() - $order->get_shipping();
$requestTracker = new WPAM_Tracking_RequestTracker();
$requestTracker->handleCheckout($order_id, $purchaseAmount);
}
示例8: get_total_shipping
/**
* Get Order shipping total
*
* @param WC_Order $order
* @return double
*/
public static function get_total_shipping(WC_Order $order)
{
if (self::is_wc_2_1()) {
return $order->get_total_shipping();
} else {
return $order->get_shipping();
}
}
示例9: get_order_items
/**
* Get order items.
*
* @param WC_Order $order Order data.
*
* @return array Items list, extra amount and shipping cost.
*/
protected function get_order_items($order)
{
$items = array();
$extra_amount = 0;
$shipping_cost = 0;
// Force only one item.
if ('yes' == $this->gateway->send_only_total) {
$items[] = array('description' => $this->sanitize_description(sprintf(__('Order %s', 'woocommerce-pagseguro'), $order->get_order_number())), 'amount' => $this->money_format($order->get_total()), 'quantity' => 1);
} else {
// Products.
if (0 < sizeof($order->get_items())) {
foreach ($order->get_items() as $order_item) {
if ($order_item['qty']) {
$item_name = $order_item['name'];
$item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
if ($meta = $item_meta->display(true, true)) {
$item_name .= ' - ' . $meta;
}
$items[] = array('description' => $this->sanitize_description($item_name), 'amount' => $this->money_format($order->get_item_total($order_item, false)), 'quantity' => $order_item['qty']);
}
}
}
// Fees.
if (0 < sizeof($order->get_fees())) {
foreach ($order->get_fees() as $fee) {
$items[] = array('description' => $this->sanitize_description($fee['name']), 'amount' => $this->money_format($fee['line_total']), 'quantity' => 1);
}
}
// Taxes.
if (0 < sizeof($order->get_taxes())) {
foreach ($order->get_taxes() as $tax) {
$items[] = array('description' => $this->sanitize_description($tax['label']), 'amount' => $this->money_format($tax['tax_amount'] + $tax['shipping_tax_amount']), 'quantity' => 1);
}
}
// Shipping Cost.
if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) {
$shipping_total = $order->get_total_shipping();
} else {
$shipping_total = $order->get_shipping();
}
if ($shipping_total > 0) {
$shipping_cost = $this->money_format($shipping_total);
}
// Discount.
if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.3', '<')) {
if (0 < $order->get_order_discount()) {
$extra_amount = '-' . $this->money_format($order->get_order_discount());
}
}
}
return array('items' => $items, 'extra_amount' => $extra_amount, 'shipping_cost' => $shipping_cost);
}
示例10: array
/**
* Google Analytics eCommerce tracking
**/
function ecommerce_tracking_code($order_id)
{
global $woocommerce;
if (is_admin() || current_user_can('manage_options') || $this->ga_ecommerce_tracking_enabled == "no") {
return;
}
$tracking_id = $this->ga_id;
if (!$tracking_id) {
return;
}
// Doing eCommerce tracking so unhook standard tracking from the footer
remove_action('wp_footer', array(&$this, 'google_tracking_code'));
// Get the order and output tracking code
$order = new WC_Order($order_id);
$loggedin = is_user_logged_in() ? 'yes' : 'no';
if (is_user_logged_in()) {
$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
$username = $current_user->user_login;
} else {
$user_id = '';
$username = __('Guest', 'woocommerce');
}
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', '<?php
echo $tracking_id;
?>
'],
['_setCustomVar', 1, 'logged-in', '<?php
echo $loggedin;
?>
', 1],
['_setCustomVar', 2, 'user-id', '<?php
echo $user_id;
?>
', 1],
['_setCustomVar', 3, 'username', '<?php
echo $username;
?>
', 1],
['_trackPageview']
);
_gaq.push(['_addTrans',
'<?php
echo $order_id;
?>
', // order ID - required
'<?php
bloginfo('name');
?>
', // affiliation or store name
'<?php
echo $order->order_total;
?>
', // total - required
'<?php
echo $order->get_total_tax();
?>
', // tax
'<?php
echo $order->get_shipping();
?>
', // shipping
'<?php
echo $order->billing_city;
?>
', // city
'<?php
echo $order->billing_state;
?>
', // state or province
'<?php
echo $order->billing_country;
?>
' // country
]);
// Order items
<?php
if ($order->get_items()) {
foreach ($order->get_items() as $item) {
$_product = $order->get_product_from_item($item);
?>
_gaq.push(['_addItem',
'<?php
echo $order_id;
?>
', // order ID - required
'<?php
if (!empty($_product->sku)) {
echo __('SKU:', 'woocommerce') . ' ' . $_product->sku;
} else {
//.........这里部分代码省略.........