isCartEnabled() ) { add_action( 'wp_enqueue_scripts', function () { // Enqueue the cart drawer script modules. wp_enqueue_script_module( '@surecart/cart' ); wp_enqueue_script_module( '@surecart/checkout' ); } ); add_action( 'template_include', array( $this, 'includeCartTemplate' ) ); } } /** * Get the icon name saved in the settings * * @return string */ public function getIconNameFromSettings() { return get_option( 'surecart_cart_icon', 'shopping-bag' ); } /** * Get the icon. * * @param 'menu'|'floating' $type Menu type. * * @return string */ public function getIcon( $type ) { $icon = $this->getIconNameFromSettings(); /** * Allow filtering of the cart menu icon. * * @param string $icon The icon. * @param string $mode The icon position. */ return apply_filters( 'sc_cart_menu_icon', $icon, $type ); } /** * Get selected ids. * * @return array|false */ public function getSelectedIds() { return get_option( 'surecart_cart_menu_selected_ids', false ); } /** * Get icon type. * * @return array|false */ public function getIconType() { return get_option( 'surecart_cart_icon_type', 'floating_icon' ); } /** * Check if cart menu is always shown. * * @return boolean */ public function isAlwaysShown() { return (bool) get_option( 'surecart_cart_menu_always_shown', true ); } /** * Is the cart enabled? */ public function isCartEnabled() { if ( apply_filters( 'sc_cart_disabled', false ) ) { return false; } return ! (bool) get_option( 'sc_slide_out_cart_disabled', false ); } /** * Get cart menu alignment. * * @return 'left'|'right */ public function getAlignment() { return (string) get_option( 'surecart_cart_menu_alignment', 'right' ); } /** * Get mode. * * @return string */ public function getMode() { $form = $this->getForm(); if ( empty( $form->ID ) ) { return ''; } return Form::getMode( $form->ID ); } /** * Add cart to menu. * * @param array $items Menu items. * @param object $args Menu args. * * @return array */ public function addCartMenu( $items, $args ) { $menu = wp_get_nav_menu_object( $args->menu ); $id = $menu ? $menu->term_id : false; // if there is no id, or the menu icon is not enabled, or the cart is disabled, return. if ( ! $id || ! $this->isMenuIconEnabled( $id ) || ! $this->isCartEnabled() ) { return $items; } $cart_menu_alignment = $this->getAlignment(); $menu = $this->menuItemTemplate(); // left or right. $items = 'right' === $cart_menu_alignment ? $items . $menu : $menu . $items; return $items; } /** * Get the menu item template. * * @return string */ public function menuItemTemplate() { $cart_menu_icon_attributes = [ 'cart_menu_always_shown' => $this->isAlwaysShown(), 'cart_icon' => $this->getIcon( 'menu' ) ?? 'shopping-bag', ]; $cart_menu_icon_block_content = ''; ob_start(); ?>