简体   繁体   English

Woocommerce中“添加到购物车”旁边的Allign Paypal按钮

[英]Allign Paypal Button next to “Add to Cart” in Woocommerce

i have custom Paypal payment button into my Woocommerce site and want to allign both buttons next one by one, like this image: 我在Woocommerce网站上有一个自定义的Paypal付款按钮,并且想要将两个按钮一个接一个地分配,如下图:

在此处输入图片说明

Currently is showing bellow add to cart button: 当前正在显示以下添加到购物车按钮:

在此处输入图片说明

i tryed to move button UP, customizing margin-top, but seems dont give effect i wanted. 我试图将按钮向上移动,自定义页边距,但是似乎没有实现我想要的效果。 This is CSS class for that button: 这是该按钮的CSS类:

.wcppec-checkout-buttons__button img {
 margin: 0 auto;
 }

i tryed to modify this is this way: 我试图修改这是这样的:

 .wcppec-checkout-buttons__button img {
 margin-top:-100px;
 }

looks like button is hidding bellow add to cart button. 好像按钮隐藏在下面,添加到购物车按钮。 Can someone to tell me where i doing wrong? 有人可以告诉我我做错了什么吗? Maybe can be used JavaScript ? 也许可以使用JavaScript? Thanks in advance. 提前致谢。

Actual problem can be seen here . 实际问题可以在这里看到。

I have managed to put it aligned to the right, like the following: 我设法将其向右对齐,如下所示: 贝宝框右对齐

To do that, I edited the HTML code using the inspector developer tools: 为此,我使用检查器开发人员工具编辑了HTML代码: 检查1

Move the div with the class wcppec-checkout-buttons woo_pp_cart_buttons_div to inside the div with the class woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-disabled . 将类别为wcppec-checkout-buttons woo_pp_cart_buttons_div的div woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-disabled类别为woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-disabled的div的内部div woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-disabled Add to CSS: 添加到CSS:

.woocommerce-variation-add-to-cart variations_button woocommerce-variation-add-to-cart-disabled { display: flex; }

If you don't know what the flex property is, I suggest reading this: w3 css flexbox property. 如果您不知道flex属性是什么,建议阅读以下内容: w3 css flexbox属性。

Also another you may have now, is why the "add to cart" box was enlarged. 您现在可能还拥有的另一个原因是为什么“添加到购物车”框被放大了。 You'll have to work on the sizing of the parent element for it stop happening. 您必须对父元素的大小进行调整,以使其停止发生。 Take a look at this question here on stackoverflow. 这里查看关于stackoverflow的这个问题。

Edit: Just read the author's comment saying he cannot edit the HTML, this probably won't work. 编辑:只需阅读作者的评论说他不能编辑HTML,这可能行不通。

The solution involves to part 解决方案涉及部分

  1. Javascript - This will be used to move the paypal button into the desired location's parent Javascript-这将用于将Paypal按钮移至所需位置的父级
  2. CSS - A few rules to adapt the desire look CSS-适应欲望外观的一些规则

Javascript 使用Javascript

Nothing complex here. 这里没什么复杂的。 Just remove the element with all its childs and append it to the destination. 只需删除元素及其所有子元素,然后将其附加到目标即可。 This has to be added on the custom JS on your WP theme. 这必须添加到您的WP主题的自定义JS上。

The window.onload will wait for your document to load before the function runs. 在该函数运行之前, window.onload将等待文档加载。

window.onload = function() { 
  const sourceElement = document.getElementsByClassName('woo_pp_cart_buttons_div')[0]; 
  const destination = document.getElementsByClassName('woocommerce-variation-add-to-cart-disabled')[0]; 
  destination.appendChild(sourceElement); 
}

CSS CSS

Just a few style rules to change the position and size of the paypal button. 仅需一些样式规则即可更改Paypal按钮的位置和大小。 Also added a media query for a breakpoint on the mobile view. 还为移动视图上的断点添加了媒体查询。

.woocommerce-variation-add-to-cart.variations_button.woocommerce-variation-add-to-cart-disabled,
.woocommerce-variation-add-to-cart.variations_button.woocommerce-variation-add-to-cart-enabled {
  display: flex;
  padding: 0;
  flex-direction: row;
  height: 39px;
  justify-content: space-between;
  align-items: center;
}

.quantity.buttons_added {
  margin: 0;
  flex-shrink: 2;
}

button.single_add_to_cart_button.button.alt.disabled.wc-variation-selection-needed,
button.single_add_to_cart_button.button.alt {
  margin: 0 20px;
  flex-basis: 200px;
}

.wcppec-checkout-buttons.woo_pp_cart_buttons_div {
  flex-shrink: 5;
  margin: 0;
}

a#woo_pp_ec_button_product {
  padding: 0;
}

.wcppec-checkout-buttons.woo_pp_cart_buttons_div a img { 
height: 38px!important; 
}

@media screen and (max-width: 580px) { 
  .woocommerce-variation-add-to-cart.variations_button.woocommerce-variation-add-to-cart-disabled,
  .woocommerce-variation-add-to-cart.variations_button.woocommerce-variation-add-to-cart-enabled {
    flex-wrap: wrap;
    justify-content: space-around;
      height: 90px;
  }

  .wcppec-checkout-buttons.woo_pp_cart_buttons_div {
    padding-top: 15px;
  }
}

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM