$product_types, true ) ) { return $settings; } $country_code = wc_format_country_state_string( $settings['preloadSettings']['general']['woocommerce_default_country'] )['country']; $country_name = WC()->countries->get_countries()[ $country_code ] ?? null; $is_jetpack_installed = in_array( 'jetpack', $settings['plugins']['installedPlugins'] ?? array(), true ); $is_wcs_installed = in_array( 'woocommerce-services', $settings['plugins']['installedPlugins'] ?? array(), true ); if ( ( 'US' === $country_code && $is_jetpack_installed ) || ( ! in_array( $country_code, array( 'CA', 'AU', 'NZ', 'SG', 'HK', 'GB', 'ES', 'IT', 'DE', 'FR', 'CL', 'AR', 'PE', 'BR', 'UY', 'GT', 'NL', 'AT', 'BE' ), true ) ) || ( 'US' === $country_code && false === $is_jetpack_installed && false === $is_wcs_installed ) ) { $zone = new \WC_Shipping_Zone(); $zone->set_zone_name( $country_name ); $zone->add_location( $country_code, 'country' ); // Method creation has no default title, use the REST API to add a title. $instance_id = $zone->add_shipping_method( 'free_shipping' ); $request = new \WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); $request->set_body_params( array( 'settings' => array( 'title' => 'Free shipping', ), ) ); rest_do_request( $request ); update_option( 'woocommerce_admin_created_default_shipping_zones', 'yes' ); Shipping::delete_zone_count_transient(); } return $settings; } /** * Adds fields so that we can store performance indicators, row settings, and chart type settings for users. * * @param array $user_data_fields User data fields. * @return array */ public function add_user_data_fields( $user_data_fields ) { return array_merge( $user_data_fields, array( 'homepage_layout', 'homepage_stats', 'task_list_tracked_started_tasks', ) ); } /** * Registers home page. */ public function register_page() { // Register a top-level item for users who cannot view the core WooCommerce menu. if ( ! self::is_admin_user() ) { wc_admin_register_page( array( 'id' => 'woocommerce-home', 'title' => __( 'WooCommerce', 'woocommerce' ), 'path' => self::MENU_SLUG, 'capability' => 'read', ) ); return; } wc_admin_register_page( array( 'id' => 'woocommerce-home', 'title' => __( 'Home', 'woocommerce' ), 'parent' => 'woocommerce', 'path' => self::MENU_SLUG, 'order' => 0, 'capability' => 'read', ) ); } /** * Check if the user can access the top-level WooCommerce item. * * @return bool */ public static function is_admin_user() { if ( ! class_exists( 'WC_Admin_Menus', false ) ) { include_once WC_ABSPATH . 'includes/admin/class-wc-admin-menus.php'; } if ( method_exists( 'WC_Admin_Menus', 'can_view_woocommerce_menu_item' ) ) { return \WC_Admin_Menus::can_view_woocommerce_menu_item() || current_user_can( 'manage_woocommerce' ); } else { // We leave this line for WC versions <= 6.2. return current_user_can( 'edit_others_shop_orders' ) || current_user_can( 'manage_woocommerce' ); } } /** * Possibly remove the WooCommerce menu item if it was purely used to access wc-admin pages. */ public function possibly_remove_woocommerce_menu() { global $menu; if ( self::is_admin_user() ) { return; } foreach ( $menu as $key => $menu_item ) { if ( self::MENU_SLUG !== $menu_item[2] || 'read' !== $menu_item[1] ) { continue; } unset( $menu[ $key ] ); } } /** * Update the WooCommerce menu structure to make our main dashboard/handler * the top level link for 'WooCommerce'. */ public function update_link_structure() { global $submenu; // User does not have capabilities to see the submenu. if ( ! current_user_can( 'manage_woocommerce' ) || empty( $submenu['woocommerce'] ) ) { return; } $wc_admin_key = null; foreach ( $submenu['woocommerce'] as $submenu_key => $submenu_item ) { if ( self::MENU_SLUG === $submenu_item[2] ) { $wc_admin_key = $submenu_key; break; } } if ( ! $wc_admin_key ) { return; } $menu = $submenu['woocommerce'][ $wc_admin_key ]; // Move menu item to top of array. unset( $submenu['woocommerce'][ $wc_admin_key ] ); array_unshift( $submenu['woocommerce'], $menu ); } /** * Preload options to prime state of the application. * * @param array $options Array of options to preload. * @return array */ public function preload_options( $options ) { $options[] = 'woocommerce_default_homepage_layout'; $options[] = 'woocommerce_admin_install_timestamp'; return $options; } }
Warning: Class "Automattic\WooCommerce\Internal\Admin\Homescreen" not found in /htdocs/wp-content/plugins/woocommerce/src/Admin/Features/Features.php on line 360
ase', array(__CLASS__, 'createPurchaseEvent'), array($order_id), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); self::enqueuePixelCode($server_event); } public static function createPurchaseEvent($order_id) { $order = wc_get_order($order_id); $content_type = 'product'; $product_ids = array(); $contents = array(); foreach ($order->get_items() as $item) { $product = wc_get_product($item->get_product_id()); if ('product_group' !== $content_type && $product->is_type('variable')) { $content_type = 'product_group'; } $quantity = $item->get_quantity(); $product_id = self::getProductId($product); $content = new Content(); $content->setProductId($product_id); $content->setQuantity($quantity); $content->setItemPrice($item->get_total() / $quantity); $contents[] = $content; $product_ids[] = $product_id; } $event_data = self::getPiiFromBillingInformation($order); $event_data['content_type'] = $content_type; $event_data['currency'] = \get_woocommerce_currency(); $event_data['value'] = $order->get_total(); $event_data['content_ids'] = $product_ids; $event_data['contents'] = $contents; return $event_data; } public static function trackAddToCartEvent( $cart_item_key, $product_id, $quantity, $variation_id) { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'AddToCart', array(__CLASS__, 'createAddToCartEvent'), array($cart_item_key, $product_id, $quantity), self::TRACKING_NAME ); // When AJAX is used to add an item to the cart // The Conversions API event should be sent inmediately // because the wp_footer action is not executed $is_ajax_request = wp_doing_ajax(); FacebookServerSideEvent::getInstance()->track($server_event, $is_ajax_request); // If it is not an ajax request // We show the pixel call in the footer // Otherwise we add a filter // to modify the ajax response // and show the fbq call in the div #fb-pxl-ajax-code if(!$is_ajax_request){ self::enqueuePixelCode($server_event); } else{ FacebookServerSideEvent::getInstance()->setPendingPixelEvent( 'addPixelCodeToAddToCartFragment', $server_event ); add_filter('woocommerce_add_to_cart_fragments', array(__CLASS__, 'addPixelCodeToAddToCartFragment')); } } public static function addPixelCodeToAddToCartFragment($fragments) { $server_event = FacebookServerSideEvent::getInstance() ->getPendingPixelEvent('addPixelCodeToAddToCartFragment'); if( !is_null($server_event) ){ $pixel_code = self::generatePixelCode($server_event, true); $fragments['#'.self::DIV_ID_FOR_AJAX_PIXEL_EVENTS] = self::getDivForAjaxPixelEvent($pixel_code); } return $fragments; } public static function createAddToCartEvent( $cart_item_key, $product_id, $quantity) { $event_data = self::getPIIFromSession(); $event_data['content_type'] = 'product'; $event_data['currency'] = \get_woocommerce_currency(); $cart_item = self::getCartItem($cart_item_key); if (!empty($cart_item_key)) { $event_data['content_ids'] = array(self::getProductId($cart_item['data'])); $event_data['value'] = self::getAddToCartValue($cart_item, $quantity); } return $event_data; } public static function trackInitiateCheckout() { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'InitiateCheckout', array(__CLASS__, 'createInitiateCheckoutEvent'), array(), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); self::enqueuePixelCode($server_event); } public static function createInitiateCheckoutEvent() { $event_data = self::getPIIFromSession(); $event_data['content_type'] = 'product'; $event_data['currency'] = \get_woocommerce_currency(); if ($cart = WC()->cart) { $event_data['num_items'] = $cart->get_cart_contents_count(); $event_data['value'] = $cart->total; $event_data['content_ids'] = self::getContentIds($cart); $event_data['contents'] = self::getContents($cart); } return $event_data; } private static function getPiiFromBillingInformation($order) { $pii = array(); $pii['first_name'] = $order->get_billing_first_name(); $pii['last_name'] = $order->get_billing_last_name(); $pii['email'] = $order->get_billing_email(); $pii['zip'] = $order->get_billing_postcode(); $pii['state'] = $order->get_billing_state(); $pii['country'] = $order->get_billing_country(); $pii['city'] = $order->get_billing_city(); $pii['phone'] = $order->get_billing_phone(); return $pii; } private static function getAddToCartValue($cart_item, $quantity) { if (!empty($cart_item)) { $price = $cart_item['line_total'] / $cart_item['quantity']; return $quantity * $price; } return null; } private static function getCartItem($cart_item_key) { if (WC()->cart) { $cart = WC()->cart->get_cart(); if (!empty($cart) && !empty($cart[$cart_item_key])) { return $cart[$cart_item_key]; } } return null; } private static function getContentIds($cart) { $product_ids = []; foreach ($cart->get_cart() as $item) { if (!empty($item['data'])) { $product_ids[] = self::getProductId($item['data']); } } return $product_ids; } private static function getContents($cart) { $contents = []; foreach ($cart->get_cart() as $item) { if (!empty($item['data']) && !empty($item['quantity'])) { $content = new Content(); $content->setProductId(self::getProductId($item['data'])); $content->setQuantity($item['quantity']); $content->setItemPrice($item['line_total'] / $item['quantity']); $contents[] = $content; } } return $contents; } private static function getProductId($product) { $woo_id = $product->get_id(); return $product->get_sku() ? $product->get_sku() . '_' . $woo_id : self::FB_ID_PREFIX . $woo_id; } private static function getPIIFromSession(){ $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $user_id = get_current_user_id(); if($user_id != 0){ $event_data['city'] = get_user_meta($user_id, 'billing_city', true); $event_data['zip'] = get_user_meta($user_id, 'billing_postcode', true); $event_data['country'] = get_user_meta($user_id, 'billing_country', true); $event_data['state'] = get_user_meta($user_id, 'billing_state', true); $event_data['phone'] = get_user_meta($user_id, 'billing_phone', true); } return array_filter($event_data); } private static function isFacebookForWooCommerceActive() { return in_array( 'facebook-for-woocommerce/facebook-for-woocommerce.php', get_option('active_plugins')); } public static function generatePixelCode($server_event, $script_tag = false){ $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME, $script_tag); $code = sprintf(" %s ", $code); return $code; } public static function enqueuePixelCode($server_event){ $code = self::generatePixelCode($server_event, false); wc_enqueue_js($code); return $code; } }
Fatal error: Uncaught Error: Class "FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce" not found in /htdocs/wp-content/plugins/official-facebook-pixel/core/FacebookWordpressPixelInjection.php:39 Stack trace: #0 /htdocs/wp-content/plugins/official-facebook-pixel/facebook-for-wordpress.php(76): FacebookPixelPlugin\Core\FacebookWordpressPixelInjection->inject() #1 /htdocs/wp-includes/class-wp-hook.php(324): FacebookPixelPlugin\FacebookForWordpress->registerPixelInjection('') #2 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #3 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #4 /htdocs/wp-settings.php(704): do_action('init') #5 /htdocs/wp-config.php(92): require_once('/htdocs/wp-sett...') #6 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #7 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #8 /htdocs/index.php(17): require('/htdocs/wp-blog...') #9 {main} thrown in /htdocs/wp-content/plugins/official-facebook-pixel/core/FacebookWordpressPixelInjection.php on line 39